Home Forums WinForms controls Xceed Grid for WinForms Grouping Question Reply To: Grouping Question

Xceed Support
Member
Post count: 5658

Here is a snippet of code that should help you get started (I added a GridControl and 2 Buttons to my form):

<code>
private void Form1_Load( object sender, EventArgs e )
{
Column col1 = new Column( “Column1” );
Column col2 = new Column( “Column2” );
Column col3 = new Column( “Column3” );
Column col4 = new Column( “Column4” );
Column col5 = new Column( “Column5” );
gridControl1.Columns.Add( col1 );
gridControl1.Columns.Add( col2 );
gridControl1.Columns.Add( col3 );
gridControl1.Columns.Add( col4 );
gridControl1.Columns.Add( col5 );

for( int i = 0; i < 30; i++ )
{
Xceed.Grid.DataRow row = gridControl1.DataRows.AddNew();
foreach( Cell cell in row.Cells )
{
cell.Value = “Item ” + (i%5).ToString() + ” : ” + cell.ParentColumn.Title;
}
row.EndEdit();
}

gridControl1.Columns[ “Column1” ].Visible = false;
}

private void butGroup_Click( object sender, EventArgs e )
{
Group groupCol1 = new Group();
groupCol1.GroupBy = “Column1”;

groupCol1.HeaderRows.Add( new GroupManagerRow() );

gridControl1.GroupTemplates.Add( groupCol1 );
gridControl1.UpdateGrouping();
}

private void butUnGroup_Click( object sender, EventArgs e )
{
gridControl1.GroupTemplates.Clear();
gridControl1.UpdateGrouping();
}
</code>

Imported from legacy forums. Posted by CharlesB (had 3142 views)