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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set Cell backcolor according their value

Thread ID:

Created:

Updated:

Platform:

Replies:

79407 Feb 6,2009 07:33 PM UTC Feb 9,2009 05:36 AM UTC WinForms 1
loading
Tags: GridControl
Lan Mo
Asked On February 6, 2009 07:33 PM UTC

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();






Rajadurai C [Syncfusion]
Replied On 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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;