Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi every one,
I want to repeat datagrid data in textboxes of another window. Data has been saved in sql databse and i want to retrieve them on the new window based on click on one datagrid row.
how can i do? thanks.
 
 
 <DataGrid Margin="0,23,0,0" AutoGenerateColumns="False" EnableRowVirtualization="True" 
                  ItemsSource="{Binding}" Name="grdPeople" VerticalContentAlignment="Center" 
                  IsReadOnly="True" DataContext="{Binding}">
 
			<DataGrid.Columns>                
                <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" Width="Auto" ></DataGridTextColumn>
                <DataGridTextColumn Binding="{Binding Path=Job}" Header="Job" Width="Auto"></DataGridTextColumn>
                <DataGridTemplateColumn Header="Picture" Width="45" >
                    <DataGridTemplateColumn.CellTemplate >
                        <DataTemplate >
                            <Image Source="{Binding Path=Picture}" Width="30" Height="30" Stretch="Uniform">                                
                            </Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
Posted 7-Jan-13 6:59am
Edited 7-Jan-13 7:22am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Define and implement some interface with an event object in it. It's very convenient to write a separate file with another part of the partial window class, then you would not need to mention the interface in different parts of this class. Implement it in one of the window. For example, a window where you grid view is can introduce and event DataGridRawSelected. Create it based on your own event arguments class (derived from System.EventArgs class) to pass all data you need to show in a different window.
 
As the instance of the first window can now be represented by an interface instance, with everything else hidden from the user, you can pass this interface reference to the second window. It should have a field in its class of the interface type. Assign this field to the first window. Now your second window have a field of the interface type, and the interface reference points to the first window, but only interface members are accessed. In the code of the second window, add a handler to the event, which is a member of the interface. An event handler will receive event arguments which carry all the information related to the selected raw, but only the information needed to be presented in a second window. Use the reference to the text boxes, which are now accessible, because the handler is the method of a second window. Show this information in these text boxes.
 
Another way around is possible: implement and interface for the second window; this interface properties should represent texts to be shown in the text boxes, but in some abstract form (just use your semantic names for the meaning of those strings), pass it in the first window, which should use the interface reference to fill in the text data.
 
However, first approach provides better isolation and better abstracts out the UI. An interface is used only for handling an event. You can consider any combination approaches.
 
I did not say anything new here; you should be able to create and implement interfaces, exchange interface instances instead of references to implementing classes/structures, define event instances and add event handlers to the invocation lists of interface instances. All of these chores is a must for any UI development. I only suggested a neatly packages and robust design of the code.
 
—SA
  Permalink  
Comments
Mohammad Hossein Shojaei at 7-Jan-13 19:53pm
   
Thanks
Sergey Alexandrovich Kryukov at 7-Jan-13 20:02pm
   
OK, will you accept the answer formally (green button)? — thanks.
Of course, if you have some follow-up questions, you are welcome to ask.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100