Reputation: 8921
Having trouble keeping expanded groupings expanded when the XtraGrid's datasource is reassigned.
BACKGROUND
Form has XtraGrid on the left and a Vertical Grid on the right. The XtraGrid is a controller for the form.
User drags a column (e.g. Customer) to the group header. Then expands several customers to see their order header detail. Then the user either:
-- clicks on one of the orders, which fetches the order detail from the database and populates the vertical grid on the right hand side of the form, where the user can make edits and then Save the changes.
OR
-- clicks on Add New on a menu which presents a blank vertical grid, which the user can complete and Save.
After the update or the insert, the datasource that populates the XtraGrid on the left hand side of the page is completely renewed -- another query is issued against the database, which returns a DataTable that is assigned to the grid's datasource property; and then the focus is set to the updated row or to the newly inserted row:
DevExpress.XtraGrid.Views.Base.ColumnView vw;
vw = MyXtraGrid.DefaultView as DevExpress.XtraGrid.Views.Base.ColumnView;
// <snip> routine to determine the row
vw.FocusedRowHandle = i
However.....
I want to leave all of the user's expanded customers expanded. So, before the Save or Insert, I invoke a SaveGridLayout method:
private void SaveGridLayout()
{
(ControllerList as DevExpress.XtraGrid.GridControl).MainView.SaveLayoutToStream(GridLayoutStream);
}
and the, after the grid's datasource has been reassigned after the update or insert, and the focused row has been reset, I invoke a RestoreGridLayout method:
private void RestoreGridLayout()
{
( ControllerList as DevExpress.XtraGrid.GridControl).MainView.RestoreLayoutFromStream(GridLayoutStream);
}
GridLayoutStream is a variable with form-scope, BTW.
But this approach is not working. The expanded groups are getting closed up. Is what I'm doing wrong evident to anyone?
Thanks
Upvotes: 1
Views: 3482
Reputation: 5340
If I am not mistaken, the XtraGrid does not preserve the information about expanded group rows. Use the approach from the How to preserve the XtraGrid View state article as a workaround to this limitation.
Upvotes: 1