In UltraWinGrid, the grouped rows are expanded using expand symbol (+). On grid refresh, again the rows are getting collapsed. How to retain the expanded state? (Note: Grouping is done based on multiple columns). While refreshing the grid (to reflected the newly added rows or any updates), i tried to use "Grid.Rows.Refresh(RefreshRow.ReloadData)". But it is not reflecting the newly added rows. How to overcome this problem?
It all depends on what you mean by "grid refresh". The Refresh method on the grid just causes the grid to paint. This will have no effect on the expanded states of the rows.
If you losing the expanded states on the rows, then you are probably re-setting the grid's data source, or doing something that causes the grid to get a Reset notification from the BindingManager. In such a case, all grid rows are destroyed and a new set or rows is created to show the new data. The grid cannot associate the old rows with the new data.
The best thing to do in a case like this is to avoid completely re-setting the data source, which is a particularly destructive operation.
Hi Mike,
I understood that the grid will be reset and expanded state will not be retained, on getting the reset notification.
My doubt is how to update the grid with the newly added rows to database and at the same time, expanded state should be retained.
Is there any way to achieve this? please let me know.
Hi,
I'm not sure what you mean by "update the grid with the newly added rows to database".
What kind of data source are you using for the grid? If your data source gets some new rows added to it, then most data sources will automatically notify bound control that this has happened and you don't have to do anything.
UltraWinGrid is binded to the DataSet, which is a disconnected DataSource. Everytime when the user access the grid, the corresponding dataset will be updated with the data from db (this will get the newly added rows to the database). Since the UltraWinGrid is binded to a (disconnected) DataSet, every-time when am retrieving data from db, i need to bind the dataset to the grid using the code given below:Grid.DataSource = DataSet;Grid.DataMember = TableName; (it denotes, which table within the corresponding DataSet)Grid.DataBind();Since the above codes are executed every time, i am not able to retain the expanded state of the grid. How to overcome this problem ?
Okay... first off, what exactly happens when you update the dataset with new information from the database? How are you doing this? Are you completely destroying the dataset and creating a new one? Are you clearing out the tables from the dataset and rebuilding them?
If you are simply adding rows to the tables in your dataset, then you do not have to do anything to get the grid to recognize those new rows. The DataSet will automatically notify the grid.
But if you are completely rebuilding the DataSet with new tables or clearing out the existing rows and re-adding them, then that will lose all of the rows in the grid and there is nothing you can do about that.
Also, calling DataBind on the grid is uneccessary and inefficient. And actually, so is setting the DataSource and DataMember seperately. You are essentially binding your grid 3 times with the code you have here. You can replace all three lines of code you have here with a single call to Grid.SetDataBinding.
I'm not sure what you mean by "not unique enough". The Value property on each GroupByRow has to be unique for the level it's on. So the Value and the level should be enough information to store the expanded state of the GroupByRow.
I am able to retain the expanded state for dataRow's, using the unique values of each rows. But, i am unable to handle the GroupByRow's. Say, the rows are grouped-by 2 or more columns. i have expanded till second level and saving the Second level's GroupByRow's value (to retain the expanded state, after reloading). But, this information is not sufficient. Because, within each group or as a whole in the grid's groups, the GroupByRow's value will not be unique enough. I am not able to find any property, which will help to identify the GroupByRow's uniquely.
The dataSet is re-built with new tables and rows are added again. In this case, how can i retain the expanded rows or groups in the grid?