Different Color in the Grid

Hi haneef!

My problem is that I have to assign the color to the Rows in the grid at runtime.

For Example:

the first 10 records may be one color
the another set of 5 records may be in another color and it continues for various group.

Thing is that i am not able to predict the no.of records for each group it depends on database.

how to handle it.I tried in different ways it leads to error when no.of records changes.

awaiting for ur reply.

Regards

Dhana

1 Reply

AD Administrator Syncfusion Team December 28, 2006 07:11 AM UTC

Hi Dhana,

Are you using GroupingGridControl? If so, you can get the group name of the record and set the color of the record depends on the group name by using QueryCellStyleInfo event. Here is a code snippet to show this.

private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
Element el=e.TableCellIdentity.DisplayElement ;
if(el != null && el.ParentGroup != null
&& el.ParentGroup.Category != null )
{
string GroupName = el.ParentGroup.Category.ToString() ;
switch(GroupName)
{
case "Market Data":
e.Style.BackColor = Color.Goldenrod;
break;
case "Data":
e.Style.BackColor = Color.Pink ;
break;
case "Credit":
e.Style.BackColor = Color.PowderBlue ;
break;
case "Market":
e.Style.BackColor = Color.Gray ;
break;
case "Credit Data":
e.Style.BackColor = Color.Red;
break;
default:
e.Style.BackColor = Color.White;
break;
}
}
}

Please refer to the attached sample for implementation.
GRoupingColors.zip

Best Regards,
Haneef

Loader.
Up arrow icon