How to keep all the groups expanded
Description:
I am using the grouping feature of the grid. I would like to have the groups always expanded, and hide the +/- sign displayed at the beginning of the rows. How can I achieve this?
Answer:
This can be implemented by handling the GroupRowCollapsing, CustomDrawGroupRow, and EndGrouping events.
By setting the e.Allow parameter of GroupRowCollapsing to false you prevent a group row from being collapsed.
private void gridView1_GroupRowCollapsing(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) {
e.Allow = false;
}
The CustomDrawGroupRow event is used to hide the expand/collapse group row buttons:
private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) {
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo info;
info = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;
info.ButtonBounds = Rectangle.Empty;
info.GroupText = " " + info.GroupText.TrimStart();
e.Cache.FillRectangle(e.Appearance.GetBackBrush(e.Cache), e.Bounds);
ObjectPainter.DrawObject(e.Cache, e.Painter, e.Info);
e.Handled = true;
}
The ExpandAllGroups method called inside the EndGrouping event handler expands all group rows when a user changes group columns.
private void gridView1_EndGrouping(object sender, System.EventArgs e) {
(sender as DevExpress.XtraGrid.Views.Grid.GridView).ExpandAllGroups();
}