Home Forums WinForms controls Xceed Grid for WinForms Grouping columns limit Reply To: Grouping columns limit

User (Old forums)
Member
Post count: 23064

You can’t limit the number of columns that can be grouped by setting a maximum.  However, you can set a specific column CanBeGrouped property to false, so it cannot be added to the GroupByRow.

e.g.:

gridControl1.Columns[ 0 ].CanBeGrouped =

false;

 

So I would suggest you change it at runtime.  You can do something like the following :

 

private void Form1_Load(object sender, System.EventArgs e)

{

gridControl1.GroupingUpdated +=

new EventHandler( gridControl1_GroupingUpdated );

} 

void gridControl1_GroupingUpdated( object sender, EventArgs e )

{

//if there is a group

if( gridControl1.Groups.Count > 0 )

{

//verify if there is another level of groups

if( gridControl1.Groups[ 0 ].Groups.Count > 0 )

{

//if so, it means 2 columns have been grouped in the GroupByRow

string firstLevelGroup = gridControl1.Groups[ 0 ].GroupBy;

string secondLevelGroup = gridControl1.Groups[ 0 ].Groups[ 0 ].GroupBy;

//so set the columns CanBeGrouped property so no more columns can be added to the GroupByRow

foreach( Column col in gridControl1.Columns )

{

if( col.FieldName != firstLevelGroup && col.FieldName != secondLevelGroup )

{

col.CanBeGrouped =

false;

}

}

}

else

{

//if not, we make sure any column can be dragged in the GroupByRow

foreach( Column col in gridControl1.Columns )

{

col.CanBeGrouped =

true;

}

}

}

}

Imported from legacy forums. Posted by André (had 791 views)