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.
Mike,
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.
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.
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.
Hi Mike,
You are right. I can do that upfront. But there are millions of rows and I don't want to show all the children up front. I only want to show the Parent rows first and ONLY when you select a parent, i can see the children. I Hope that helps in understanding the issue.
Hi Scott,
I'm a little confused by what you are trying to do. If you simply want to show a hierarchy in the grid, then you can create a DataSet with two tables and a relationship and bind it to the grid. That's it... you don't have to handle events and add things in when the row is expanded.
It seems like you are jumping through hoops to make this much more complicated than it should be. Is there some reason you need to do that?