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

GridDataBoundGrid single cell operations

I have a similar question to a previous one. I need to change the backgroud color of a sinlge cell in a GridDataBoundGrid, based on the most recent value of that cell's contents. What's the most efficient way to do this?

2 Replies

AD Administrator Syncfusion Team January 28, 2003 07:18 AM UTC

Handle PrepareViewStyleInfo and getting the value to be tested from the passed-in style. In your handler, you would conditionally set e.Style.Color by testing the cell value (or cell text) based on whether the e.ColIndex and e.RowIndex pointed to your test cell.
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
	//test cell 1,4
	if(e.ColIndex == 4 && e.RowIndex == 1)
	{
		try
		{
			//this assumes cell is an int
			int cellValue = int.Parse(e.Style.Text);
			if(cellValue > 10)
				e.Style.BackColor = Color.Red;
		}
		catch{}//empty
	}
}


BK Bill Korchinski January 28, 2003 01:58 PM UTC

Works great- thanks!

Loader.
Live Chat Icon For mobile
Up arrow icon