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.
C#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:
C#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.
C#private void gridView1_EndGrouping(object sender, System.EventArgs e) {
(sender as DevExpress.XtraGrid.Views.Grid.GridView).ExpandAllGroups();
}
Any better way?
Hi,
This approach is still actual. Would you please clarify what difficulties you faced with it?
e.Style doesn't seem to exist in RowObjectCustomDrawEventArgs
How to do this?
Hello,
Thank you for pointing out this issue to us. It seems that an outdated code snippet was used in this Knowledge Base article. I have modified it based on the How to keep all the groups expanded example. Feel free to contact us in case of any further questions.