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
close icon

Chage GDBG's cell color

i try this code: this.gridDataBoundGrid[8,10].BackColor=Color.Red; but can not change cell color. Why????????

1 Reply

AD Administrator Syncfusion Team August 21, 2003 04:57 AM UTC

In a GridDataBoundGrid, you cannot set cell specific properties (other than CellValue or Text) using an indexer as in your sample code. The reason is that in a GridDataBoundGrid, 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. So, in order to set cell specific properties in a GriDDataBoundGrid, you must catch the PrepareViewStyleInfo event (or Model.QueryCellInfo event). In your handler, you check e.RowIndex and e.ColIndex, and if these point to some cell you want to change, you set e.Style to the value you want.
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if(e.ColIndex == 2 && e.RowIndex == 2)
	{
		e.Style.BackColor = Color.Red;
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon