Hi,
I have the following problem. I present the user a grid. This grid is a usercontrol with an UltraGrid and a BindingNavigator.
It is connect with the data like this:
this.oDataAdapter = new SqlDataAdapter();this.oDataAdapter.SelectCommand = oCommand;this.oDataAdapter.Fill(this.oTableGrid);this.oBindingSource = new BindingSource();this.oBindingSource.DataSource = this.oTableGrid;this.ultraGrid1.DataSource = this.oBindingSource;this.bindingNavigator1.BindingSource = this.oBindingSource;
Now when a row needs editing, the user doubleclicks and a form is generated ( my app is datadriven ). For this form the data is first reread from the database. I cannot share the BindingSource of the grid, as often a view is displayed and not every view is editable.After editing, the modified data is written to the database, so I need to reread the data for the grid to be updated. Like this:this.oTableGrid.Clear();this.oDataAdapter.Fill(this.oTableGrid);
This works, but gives me the grid in the start position. A grouping is still active, but after rereading the data, the data of the previous expanded group needs to be expanded again.
Is there a way to restore the layout like how it was before editing? I have tried to do it with saving and loading a layout file
this.ultraGrid1.DisplayLayout.Save(Filename);
but this does not work in for me in this situation.Another thing I have tried without success is this:this.ultraGrid1.ActiveRow.Refresh(RefreshRow.ReloadData);this.ultraGrid1.ActiveRow.Refresh(RefreshRow.RefreshDisplay);
Can anyone give me a hint how to solve this problem?
kind regards,
Erik Visser
Hi Erik,
It's basically the same thing. The expanded state of a row is a state of the row and the grid cannot maintain this state when you reset the data source. GroupByRows are even worse, because they don't even exist in the data source.
The best thing to do is to avoid resetting the data source if at all possible. If you can't do that, then you will have to store the expanded state of each row yourself and restore them afterward.
Hi Mike, Thanks very much!!
Perhaps i did not make myself (or my problem...) clear enough. Let me try again in other words.
The problem is that when a grid has the outlookgrouping enabled and the user groups by dragging a column to the grouping area, the rows of the grid are folded (not sure if this is the right word, I mean the oposit of expanded) So now the user expands a group and edits a row.
When the table is cleared and reread, the grid shows all groups folded again, where I would like to see at least one group expanded.
Any solutions for this?
Erik
The grid layout does not (and cannot) include any row-level properties or state information. The grid cannot possibly know that the row it had in the original set of data is the same as some new row (which is a completely new object) in a new table of data.
So if you want to maintain the scroll position of the grid, you will have to store some key information about the row at the top of the grid before you clear the table, then find the new row with that same key info and scroll to it afterward.
To get or set the row, you can use grid.ActiveRowScrollRegion.FirstRow.