Example E828
Visible to All Users

WinForms Data Grid - Keep all groups expanded

This example automatically expands all group rows on application startup and hides expand/collapse buttons to prevent users from collapsing group rows.

The GroupRowCollapsing event is handled to prevent users from collapsing group rows:

C#
private void gridView1_GroupRowCollapsing(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) { e.Allow = false; }

The CustomDrawGroupRow event is handled to hide expand/collapse 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; }

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

KeepGroupsExpanded/Form1.cs(vb)
C#
using DevExpress.Utils.Drawing; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace KeepGroupsExpanded { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { new DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1); gridView1.Columns["Discontinued"].GroupIndex = 0; gridView1.ExpandAllGroups(); gridView1.OptionsMenu.EnableGroupPanelMenu = false; } 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; } private void gridView1_GroupRowCollapsing(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) { e.Allow = false; } } }

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.