Background:I have an application that contains the UltraWinGrid, and there is enough data to cause a vertical scroll bar, thats fine, the scrolling works fine.
I want to double click rows form the UltraWinGrid to cause a showdialog of a form, works fine.
When the dialog form shows up, and I then close it, I re-assign the UltraWinGrid datasource from the database.
Problem:When I close the dialog form and re-assign the datasource from the DataTable, the UltraWinGrid goes back to the top, and ignores the fact that I had it scrolled down.
Can somebody please help me with this?
i guess you can save the layout of the grid before setting the datasource to null, then load it after that. this will keep the grouping, sorting...
ultraGrid1.DisplayLayout.SaveAsXml(ms);
ultraGrid1.DataSource = null;
ultraGrid1.DataSource = dt;
ms.Position = 0;
ultraGrid1.DisplayLayout.LoadFromXml(ms);
but this wont re-expand the expanded rows.
i guess you should loop into them before and save the indexes of the expanded rows then loop again and re-expand them
Thanks guys, this works if there is no group by (without drag a column header here to group by that column).
Sorry, I didn't explain this in the original post.
I have "drag a column" enabled.
Is there a way to capture the expanded rows and then re-expand them again if they are still available?
If you set the grid's DataSource, then the grid has no choice but to throw away the old layout and create a new one. So all of the columns and rows are destroyed and a whole new set are created for the new DataSource.
Hady's suggestion should work, assuming that you didn't add or remove any rows from the data and that the order of the rows in the data source remains the same.
But a better way to handle this would be to simply update the data source the grid is bound to instead of recreating the entire thing.
before you change the datasource save the following in a variable:
pos = ultraGrid1.Rows.IndexOf(ultraGrid1.ActiveRowScrollRegion.FirstRow);
after you change the datasource, set the following:
ultraGrid1.ActiveRowScrollRegion.FirstRow = ultraGrid1.Rows[pos];