KB Article A1497
Visible to All Users

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.

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(); }
Show previous comments (1)
DevExpress Support Team 8 years ago

    Hi,

    This approach is still actual. Would you please clarify what difficulties you faced with it?

    G G
    Government Data Miner 7 years ago

      e.Style doesn't seem to exist in RowObjectCustomDrawEventArgs

      How to do this?

      DevExpress Support Team 7 years ago

        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.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.