Hi,
I have an UltraWinGrid on a windows form, to which I bind a dataset to display a data.
When I click on any one of the rows by clicking the '+' symbol, I must display an indented set of at least one or more rows as a child row.
Here's my approach:
(a) Get a new dataset containing only those child rows.
(b) Create a parent child relationship constraint with the existing main dataset and bind it to the grid.
If the above approach is not the best, Please specify what can be the best approach to do this.
Thanks in advance,
Scott.
Hello,
I bind the grid to a dataset which only has one table with no child tables. Now inside the mygrid_BeforeRowExpanded event, I create a new dataset which has the same data as the current dataset plus child relation constraint by using DataRelation. Now the dataset has two tables. One is parent and the other is child with a unique key.
I now call mygrid.DataSource = newdataset;
When I execute it and try clicking the '+' sign this does not show any child rows. It only shows the basic grid with parent rows.
Am I missing any thing. Please help.
Thanks,
Adding to the above, If I place the code in a Button click event, it properly displays the parent child as a related view on the Grid. However, if i do this on a BeforeRowExpanded event, it does not.
Well, changing the data structure of the grid's data source is generally not a good way to do things, because it probably causes the data source to send a Reset notification which will cause the grid to lose all state information.
If you want to load the data in the grid on-demand, then the best way to do it would be to use the UltraDataSource as a sort've intermediary between the grid and the "real" data source. The UltraDataSource has functionality to allow you to get the data as needed. It fired events to let you know when rows have been requested.
There's a sample in the WinGrid Samples Explorer and also under the UltraDataSource samples called the "Virtual Mode sample" that demonstrates this technique.
If you don't want to go that route, then I recommend setting up the DataSet with the 2 tables and a RelationShip up front, and then use the BeforeRowExpanded event to simply fill the child table with the rows it needs for the current parent row.
Mike,
If I follow the BeforeRowExpanded approach, here is what I am doing:
(a)Create Dataset that has a DataRelation of parent and children (now the children table is empty).
(b)Bind this to the grid.
(c)Click any row and handle BeforeEventHandled in which,
(d)Get Child Rows in a datatable.
(e)Merge that datatable with the parent datatable (get parentTable by using this.myGrid.DataSource property).
(f)Bind that dataset to the grid by saying this.mygrid.datasource = mergedDataSet
It does not show the children still. Am I missing anything.
As per your suggestion, I am following the approach of creating parent/child datarelation
upfront with empty children and then binding it to the grid.
The grid does not display the children when I proceed with the above approach.
When it gets binded the first time, it has the parent child relationship with children
table being empty. However, when I click a row, inside "BeforeRowExpanded" event,
the dataset gets changed altogether
with the children now having some rows. Binding this does not cause the grid to
display any children.
Is there a specific method or property that you specify? In other words, is there something that causes the grid to reset its contents inside the row event ? All i do is set the datasource property of the wingrid to the new dataset which HAS parent child datatables in it.
There is no way this will work by setting the grid's DataSource. Setting the DataSource will cause the grid to destroy all rows and columns and rebuild itself based on the new data source. So it will not be able to maintain the states of the expanded row.
My sugesstion is to create the data structure with a 2-level hierarchy up-front. Then you can load the data inot your data source as you need it when rows are expanded.
But the DataBinding in DotNet is really not set up to load on-demand, and I suspect there may be other issues getting this to work, which is why you might also want to use the UltraDataSource.
Either way, though, you are really kind've fighting against the way the DotNet Framework is designed.
Is there anyway to display a BOM a parent having children and tghe children potentially having more children within a grid
Hi Scott,
i am writting a similar solution to this and it happens to work too but i have the same problem with duplicate rows. Have you reached to a solution for this issue?
thanks,
i am trying the same thing. Could you give us more details about the correct solution?
Marova
The child list now appears in the grid. All I did is
(a)Get the current dataset (having parent/child relation) .
(b)Add child rows to the child datatable inside it.
(c)use the statement setDataBindings(datasource,""); inside BeforeRowExpanded event.
It now shows the rows. The only issue now would be to make sure it won't add duplicate rows
again and again whenever the BeforeRowExpanded event happens.
Thanks a lot for your help Mike.
For you initial question, Yes the grid does have its datasource containing a second child table. However, it does not expand the children as there are zero rows in that table. Hope it helps.