How to set programically Infragistics ultraGrid headers groups
Infragistics ultragrid is very flexible control.
One of nice option is header groups and levels which is not very common knowledge.
Grouped columns look like this:
To archieve that the easiest way is use built-in grid's designer.
But if you want to do the same in runtime (set groups programically) you can look at below code snippet:
// Create data table
DataTable dt = new DataTable();
dt.Columns.Add("First Name");
dt.Columns.Add("Second Name");
dt.Columns.Add("Salary");
dt.Columns.Add("Taxes");
dt.Rows.Add("Joe","Smith",120000,1000);
dt.Rows.Add("Mariah","Carry",1500000,10000);
// Bind Datasource
ultraGrid1.DataSource = dt;
// Create Groups
Infragistics.Win.UltraWinGrid.UltraGridGroup group1 = new Infragistics.Win.UltraWinGrid.UltraGridGroup( "Personal Info",1); // key + unique id
Infragistics.Win.UltraWinGrid.UltraGridGroup group2 = new Infragistics.Win.UltraWinGrid.UltraGridGroup( "Salary Info",2);
// Add Groups to BAND
ultraGrid1.DisplayLayout.Bands[0].Groups.Add( group1 );
ultraGrid1.DisplayLayout.Bands[0].Groups.Add( group2 );
// *** Assign columns to groups **
// option 1 Through gropus Columns
group1.Columns.Add( ultraGrid1.DisplayLayout.Bands[0].Columns[0] );
group1.Columns.Add( ultraGrid1.DisplayLayout.Bands[0].Columns[1] );
group2.Columns.Add( ultraGrid1.DisplayLayout.Bands[0].Columns[2] );
group2.Columns.Add( ultraGrid1.DisplayLayout.Bands[0].Columns[3] );
// option 2 Columns group
//ultraGrid1.DisplayLayout.Bands[0].Columns[0] .Group = group1;
Labels: Infragistics ultraGrid
2 Comments:
Thanks for sharing that. Very helpful.
Thanks for the example. but Group Header text alignment is not in center. I have applied the below line to do this- please check-
group.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Center;
but not able to text alignment in center. Please share.
Thanks :)
Post a Comment
Subscribe to Post Comments [Atom]
<< Home