ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Hierarchical Data Grid View Selected Row
    카테고리 없음 2020. 2. 15. 22:10

    OK,We've all seen them. 3rd party component grids with the first column looking very much like a 'tree view' selection and the other columns are text, images etc. The data usually has some relationship such as customer and orders. So when looking at the datagrid'collapsed' you see a customer. When you 'expand' that row you see all their orders in another datagrid. I have read alot of interesting and in some cases contradictory articles but none just flat out tell you how to get the relationship bound to the grid.I have written my WPF grid as such. OK I'm lost again.

    I have a parent DataGrid and it has customers. I WANT to have in the first column of the parent grid a triangle, plus sign, whatever. In the rest of the columns data about the customers. When the user says I'd like to see what order(s)customer jkl has placed they would click on the plus sign, the arrow whatever and then the child grid would show revealing their orders.

    I have both customers and orders in a dataset. I have a single relationship defined between the parent and child columnsof the table so my data is all set to go.

    View

    Data Grid View Example

    Hierarchical Data Grid View Selected Row

    I just am lost.as you've noticed.about how to get the grid to show this relationship.As I read your code.and I could be totally wrong, I see that you setup a tree. Then you define (i'm guessing because you don't flat say it) that my parent grid is added to the TREE datatemplate, and then I setup a child templated but it won't be nestedin the parent and the parent grid will be part of the tree where I want the reverse.I would like the tree to be a column in the parent grid and the child table to show as a nested grid under the selected row.I hope I'm making sense.JB. OK I'm really not helping you help me here.

    Selected

    Let me try it this way. 2 parts.Part1. How do I structure my Datagrid in XAML. My code is still the same as the original post. When I click on a row for the 'row details' my second grid shows but there is no data in it. Now this could be because my XAML is wrong and I shouldn't be puttingmy child grid in the row details but it seems very logical so I did it that way.

    What I am ultimately after is something like this only of course I don't want to use 3rd party controls. Also I know the link is for asp.net it's just an example of what I wantedmy grid to do in the end.Part 2. In code I have 2 datatables from different sources. I have the datatables in a dataset and have established a parent / child relationship between the two. So now I have what I thought would be sufficiently related data.

    If I bind the parentgrid to the parent table will WPF through Msoft magic know to traverse that relationship and populate the row details child grid with the related records from the child table? I didn't think so so I figured there must something more concrete that I have todo in my binding to let each know where to get it's data from.Does that make more sense???I appreciate your patience with me.JB. I think that's my question too! Yes the main grid populates. The grid in the RowDetails template is empty.

    The single line of c# code does the binding for the parent grid to the parent table in the dataset. It seems very logical to me that the grid in theRowDetails template is empty since it has no clue where to get it's data from.and that is my question.

    How do I tell the child grid get your data from table XYZ. Further it would seem that I need to specify the relationship column so that when the parentgrid is selected the data that is shown in the details grid is the proper records matching the 'key' column in the parent table.For example do I bind Parent grid ItemsSource to Parent Table. Do I then bind row details grid to child table. Do I then specify the relationship column between the two and Msoft handles the automatic selection of the proper rows when the RowDetails gridis shown?

    So it would look something like this.(THIS IS MADE UP CODE TO SHOW MY THINKING). Hi zzpluralza,After reading through the discussion here I think you want implement a collapsible DataGrid for its RowDetails.In order to implement this feature you could take advantage of DataTemplate for RowDetails and switch RowDetailsVisibility in toggle button click event. Here is one document for how to control layout of RowDetails, though it's Sliverlightrelated, you could benefit from it. Please refer toAnd I wrote a simple demo for you to show how this could be done, here we go,XAML.

Designed by Tistory.