Hi,
i would like to display the data of the datatable-row that is represented by the selecteditem of TreeView1 on a second form.
So my first question is how do i transmit the selecteditem to Form2
And my next question is, how do i access the data of the underlying table Treeview1 is bound to?(on Form2 of course)
All i could find out until now, is that Treview1.selecteditem returns a System.Data.DataRowView.
My intention is to edit (add, delete, update) the data on the second form, to save it and then to return to form1 with the updated data.
thanks,
Jeiss
Loading
JeissPosted Jan 24, 2011, 3:20 PM
In this first window there is a treeview and a few buttons. The treeview is bound in the way that the header of the treeview shows data (fields) from the parent table of a database. Expanding (opening) the treeview shows the datarows of the child datatable. This "childdata" is not displayed in a datagridview but in "stacked" textblocks in a stackpanel-element. And what i am trying to do is to open a second (new) window where the data (the one from the parent table and the one from the child table as well) is displayed in order to edit, modifie or change it.
Thanks,
Jeiss
Dorababu MekaPosted Jan 24, 2011, 10:58 AM
JeissPosted Jan 22, 2011, 8:21 AM
Yes you are right, the treeview has a selecteditem and it returns a System.Data.DataRowView.
At this time i am asking myself if it is a good idea to pass anything to the Window i want to open. Anyhow, if i want to save the changes the user makes on the second window the controls on this second window will have to be bound to the tables. And so there must be a way to access what was the current property of the Forms applications....
So, if anybody has an idea or suggestion..
Thanks in advance,
Jeiss
Dorababu MekaPosted Jan 22, 2011, 7:41 AM
I will give you an idea tree view will have the property like selected item or some thing. WHile you are selecting store that selected item to a string and pass it to the required form as i said and on the later form you can do what ever code you like
JeissPosted Jan 22, 2011, 7:36 AM
So, i'm trying to make a little application for my own. The most important part is this bound TreeView. it is bound to two related tables of a dataset. This dataset is part of the application.
So here comes the code. Tell me if you need the code behind (visual basic)
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="400" Width="550" xmlns:my="clr-namespace:TreeView_Relation">
<Window.Resources>
<DataTemplate x:Key="ProductTemplate" >
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Sequence}" FontWeight="Bold" Margin="3,0,0,0">.)TextBlock>
<TextBlock Text="{Binding Title}" TextDecorations="underline" FontWeight="Bold" Margin="10,0,0,0">:TextBlock>
StackPanel>
<StackPanel Orientation="Horizontal" Height="25">
<TextBlock Text="{Binding WorkCenter}" Margin="30,0,0,0">;TextBlock>
<TextBlock Text="{Binding Instructions}" Margin="10,0,0,0">TextBlock>
StackPanel>
StackPanel>
DataTemplate>
<HierarchicalDataTemplate x:Key="CategoryTemplate"
ItemsSource="{Binding FK_ArticleNbr_Routing}"
ItemTemplate="{StaticResource ProductTemplate}">
<TextBlock Text="{Binding Article}" Foreground="Red" FontWeight="Bold">TextBlock>
HierarchicalDataTemplate>
<my:GammesDataSet x:Key="GammesDataSet" />
<CollectionViewSource x:Key="ArticleNbrViewSource" Source="{Binding Path=ArticleNbr, Source={StaticResource GammesDataSet}}" />
<CollectionViewSource x:Key="ArticleNbrRoutingViewSource" Source="{Binding Path=FK_ArticleNbr_Routing, Source={StaticResource ArticleNbrViewSource}}" />
Window.Resources>
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<Button HorizontalAlignment="Left" Name="Editbutton" Height="23" Margin="10,0,5,5">
Edit ItemButton>
<Button HorizontalAlignment="Left" Name="PrintPrevButton" Height="23" Margin="10,0,5,5">
Print previewButton>
<Button HorizontalAlignment="Right" Name="CloseButton" Height="23" Margin="10,0,5,5">
closeButton>
StackPanel>
<TreeView Margin="10,20,10,35" Name="TreeView1"
ItemsSource="{Binding ArticleNbr}"
ItemTemplate="{StaticResource CategoryTemplate}" />
Grid>
Window>
Thanks,
Jeiss
Dorababu MekaPosted Jan 22, 2011, 7:19 AM
JeissPosted Jan 22, 2011, 7:07 AM
thank you for your fast answer.
There are a few little problems...
Fist of all i really don't know much about C#-coding(i'm used to coding in Visual Basic.) And anyhow i noticed an error in the tread's tilte, i mean windows, and not forms! So changed the title of my tread. Sorry!!!
So when i use your code (after online-translation) i get an error saying that Selectednode is not a member of System.Windows.Controls.treeview.....
And the second thing i wonder about is, if i pass a single (not single as a Type, i mean only one string) string to the second Window, how can i then access the other fields of the DataRow of the "current" datarow in the second Window. Did i miss something? ;-)
Thank you,
Jeiss
Dorababu MekaPosted Jan 22, 2011, 6:24 AM
on that form while initializing check for the string if it is the required one for you do the operation what ever u need..
sample code
form1 : string strselected=treeview.selectednode.tostring();
form2.show(s);
form2