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.
In the beginning when I bind the parent rows, the child datatable does not has any rows (but it has a datarelation). Hence the children can't be seen upfront i.e. during initial grid bind. However, when i debug the code and do a quick watch on the Grid.Datasource, there are 2 tables with rows shown.
Now inside the BeforeRowExpanded event, you mentioned to CHANGE the existing dataset by adding child datatable and then bind it. Technically, HOW DO I APPLY this new dataset to the grid. in other words what statement does the job of updating the grid. If I choose the .Datasource property then it destroys everything then how do i set this modified dataset to the grid. How does the grid know that the dataset is modified now and It needs to reload new items. Please specify.
iamscotthetfield said:(c)When a row is clicked, inside BeforeRowExpanded event, CREATE A NEW DATASET that gets two different datatables, merges them, sets datarelation and i assign that to the grid's datasource.
If you are changing the DataSource on the grid and the grid is not displaying the data in that data source, then I'm afraid I have no explanation for that. Are you certain that the data source actually contains the child rows? Does it work if you simply bind the grid to this hierarchical data source initially, without doing it inside the grid events?
In any case, what you are doing here is not going to work. Even if the grid updated, setting the grid's DataSource property is an extremely destructive process. All rows, columns, bands, and the grid layout will be destroyed and an entirely new set of them will be created in order to display the new data source. You will lose all state information, any pending changes, layout information, etc. It does not matter if the structure is the same. The user would be unable to expand the row because the row would be destroyed every time they clicked on the expansion indicator.
You should not have to set the grid's DataSource, though. If you simply add the necessary child rows to the existing child table in the DataSet, then that should be sufficient and a whole lot less destructive, not to mention far more efficient.
Hi Mike
This is what I am doing as per what you mentioned.
(a)Create a dataset that has parent rows. Add a datatable which has no rows and shows an empty child table to this dataset.
(b)Set up relationships and bind it to the grid. The grid now only shows parent rows.
(c)When a row is clicked, inside BeforeRowExpanded event, CREATE A NEW DATASET that gets two different datatables, merges them, sets datarelation and i assign that to the grid's datasource.
(d)I still do not see any child rows.
Notice that I am CREATING another dataset but has same child/parent structure as the one that i binded to the grid initially. Am i supposed to use the SAME dataset that was used to bind the grid initially? If yes in what way. Do i need to keep a form variable dataset type and assign it. Please specify.
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 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.