It looks like UltraGrid is re-using row UI including if the row is already expanded. When refreshing with new data, I need to collapse all the rows. There seems to be some performance issue when calling CollapseAll while the grid is populated.
Is there a trick to reset the grid when the DataSource refreshes its data?
Hi,
I'm not sure I understand what you are asking. You asked how to collapse all the rows, but your post already mentions the CollapseAll method and that's how you do it, so I don' know what the question is.
The grid does re-use the UIElement for efficiency. Why is that a problem? Re-using the row elements doesn't have anything to do with the expanded state of the row.
Do you mean that you are binding the grid to a new data source that contains some of the data objects as the old data source did? In that case, the grid will try to re-use the same row specifically so that it does maintain the states like selected and expanded.
In a case like that, you could first set the grid's DataSource to null before you set it to the new DataSource. This will lose the Layout, too, but you can save and restore it.
UltraGridLayout savedLayout = this.ultraGrid1.DisplayLayout.Clone(); this.ultraGrid1.DataSource = null; this.ultraGrid1.DataSource = myNewDataSource; this.ultraGrid1.DisplayLayout.CopyFrom(savedLayout);
I'm loading data to a parent-child grid. The child rows are initially loaded using dummy rows then the true rows are retrieved during the BeforeExpanded event of the row. If I load a new set of data to the grid, any previously expanded rows will stay expanded and will display the dummy rows, so I call CollapseAll after.
Okay... but I still don't understand what the problem is. There's just not enough information here for me to go on. What do you mean by "using dummy rows"? What's a dummy row? Fake rows in your data source? I assume you would only need one before parent row, but I'm not really clear on why you would need a dummy row at all.
When you say "load a new set of data into the grid", what does that mean? If you are loading child data in BeforeRowExpanded, then you don't need to set the DataSource of the grid to a completely new data source, all you would have to do is populate the child rows within the data source for that particular parent row.
I use a dummy row because it is the only way I can think of that will display the expand (plus sign) button of the parent shows up. A dummy row is just a row with only the primary key/keys populated and the rest of the fields are not assigned.
When I load a new set of data into the grid, I mean that I fetched a new set of parent and dummy child data different from what is currently bound to the grid. If I don't call Rows:CollapseAll(TRUE) after filling the DataSet with new data, any expanded rows will remain expanded but it will also display the dummy row (since this will only be populated with real rows during the BeforeRowExpanded event).
The problem is that I start to see some performance issue with calling Rows:CollapseAll(TRUE) when there are quite few parent rows. I'm asking if there is a way to reset the grid back to collapsed state without calling Rows:CollapseAll(TRUE).
We seem to be going in circles here. I understand what you are describing, but I don't know why that's happening in your grid. Unless you are re-using the same data source rows when you re-populate the data, then there's no way the grid could possibly be re-using the same row objects and maintaining the expanded state. I have never seen that happen and I don't see how it's even possible.
If you can provide a small sample project demonstrating the behavior, we can check it out, but without being able to see it, I don't know what's going on.
It doesn't seem to display if the parent row has no child row. I'll verify the settings.
As for the actual issue, I'm populating the grid with completely new set of parent rows, and it is keeping the expanded state of the rows from the previous view. It looks like the grid is reusing the UI object. Since it is a new set of parent rows, I don't want the expanded state of the rows to be retained. The DataSource is just a DataSet and is being repopulated using the Fill() method.
jquerijero said:I use a dummy row because it is the only way I can think of that will display the expand (plus sign) button of the parent shows up. A dummy row is just a row with only the primary key/keys populated and the rest of the fields are not assigned.
The WinGrid shows an expansion indicator on every parent row until the user clicks on it. This is the default behavior, and you don't need to have a dummy row in place to get it to work. It's possible that you may have changed this behavior using the ExpansionIndicators property on the Override, but I can't see why you would do that and then jump through hoops to add a dummy row just to show the Expansion indicators.
jquerijero said:When I load a new set of data into the grid, I mean that I fetched a new set of parent and dummy child data different from what is currently bound to the grid. If I don't call Rows:CollapseAll(TRUE) after filling the DataSet with new data, any expanded rows will remain expanded but it will also display the dummy row (since this will only be populated with real rows during the BeforeRowExpanded event).
If all you need to do is populate the parent row with new child rows, then why replace the parent rows? That seems very inefficient, destructive, and unnecessary. If you are removing all of the existing rows and adding new ones, then I don't see how the grid could be maintaining the expanded state of the rows - since those rows no longer exists. Are you sure something in your code isn't doing that? And why would you want all of the parent rows collapsed, anyway? If the user expands a parent row and you populate the child rows, wouldn't you want that row to still be expanded? Of course, it might depend on exactly what you are doing - it's not clear how you are re-populating the data source, or what kind of data source you are using.
Also... I can't see any reason why calling CollapseAll would cause any kind of performance hit. All this method does it set a flag on the row. How many rows do you have?
I don't know the requirements of your application, but you seem to be going to a great deal of trouble to do something that seems like it should be relatively simple. And a lot of what you are describing here doesn't jive with what I know about the behavior of the WinGrid. Are you sure it's UltraWinGrid you are using and not some other control like WebGrid?