Hello,
I have a XtraGrid with hierarchical rows (two levels). The datasource of this grid is a DataTable, which provide master rows. Dynamically, I add detail rows to some master rows (using the events MasterRowGetChildList and MasterRowExpanded of the XtraGrid). The display is OK. However, when I add, modify or delete rows in the DataTable, the write the instruction myDataTable.AcceptChanges() to validate the operations, the master rows expanded are automatically collapsed. Please, can you provide me a solution to keep expanded the master rows when I accept changes on the DataTable ?
Sincerly,
We have closed this ticket because another page addresses its subject:
Sub-detail grid collapsing after AcceptChangesMaster rows in a hierarchical XtraGrid are collapsed where I accept the changes on a DataTable
Answers approved by DevExpress Support
Hi,
We have researched this issue and realized that the GridView collapsed its master rows because it received the ListChanged event from the datasource with the ListChangedType.Reset parameter. In this situation, the GridView returns into its initial state. This is the only appropriate reaction to this event, because it is not possible to predict changes made in the datasource.
Thus, this behavior is by design.
To avoid the issue with the GridView row collapsing, you can simply expand a corresponding master row via the GridView.ExpandMasterRow method. Look at the following code:
C#int iFocusedRowHandle = gridView2.FocusedRowHandle;
ds.AcceptChanges();
gridView2.ExpandMasterRow(iFocusedRowHandle);
The most common approach to saving and restoring the GridView state is described in the following article: How to preserve the XtraGrid View state.
I hope you find this information helpful. Feel free to contact us if you need any further assistance.