We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set Cell backcolor according their value

Hi There,

When I click on a "Display Color" button, I want to set "Area" column cell's backcolor to RED OR WHITE according their value for all rows in Grouping Grid Control.

I have used these line of code, but they do not work, no color changes.

I want to put codes in Button click event instead of putting them in GGC event like QueryCellStyleInfo.

do you have any idea to do so?

Thanks,

Lan

//gdBase is Grouping Grid Control
//for all visible rows in GGC, set column "Area" backcolor to
//RED if it is <100, WHITE if it is >=100
int ColIndex = gdBase.TableDescriptor.VisibleColumns.IndexOf( "Area" );
ColIndex = gdBase.TableDescriptor.FieldToColIndex( ColIndex );
foreach (Record rec in this.gdBase.Table.FilteredRecords)
{
int RowIndex = gdBase.Table.DisplayElements.IndexOf(rec);

GridTableCellStyleInfo style =gdBase.TableModel[RowIndex,ColIndex];

//test area value
object oVal=rec.GetValue("Area");
if (oVal==null || oVal==DBNull.Value || Convert.ToInt32(oVal)<100)
{
//red
style.BackColor=Color.Red;

}
else
{
//white
style.BackColor=Color.White;
}
}
gdBase.Refresh();






1 Reply

RC Rajadurai C Syncfusion Team February 9, 2009 05:36 AM UTC

Hi Lan,

Thanks for your interest in Syncfusion products.

The cell specific properties like BackColor (other than CellValue or Text) cannot be set using an indexer like this.gridGroupingControl1.TableModel[4,3].BackColor=Color.Red. In ggc, the only data storage is the bound datasource. That only holds a single value. It does not hold TextColor, or Backcolor, or any of the other many cell specific properties.

Inorder to set cellspecific properties in ggc, you have to handle QueryCellStyleInfo event handler. However, you can control this event to be fired through a button click event based on your own settings.

Please refer to the following code snippet in which the code within the QueryCellStyleInfo event get executed only when the button click event occurs.

bool b = false;
//button click event
private void button1_Click(object sender, EventArgs e)
{
b = true;
this.gridGroupingControl1.TableControl.Refresh();
}

//QueryCellStyleInfo event
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if(b)
{
if (e.TableCellIdentity.ColIndex == 5 && e.TableCellIdentity.RowIndex > 3)
{
if (int.Parse(e.Style.Text) > 75)
e.Style.BackColor = Color.Blue;
else
e.Style.BackColor = Color.Pink;
}
}
}


Regards,
Rajadurai


Loader.
Live Chat Icon For mobile
Up arrow icon