I need to change the background color of a cell in a GridDataBoundGrid.
I do it depending on the value of another cell in the grid.
I found an example on this site that changes a cell backcolor depending on it''s own value, I tried to modify it a little to get it to change the backcolor of the cell and the preceding one in the same row. (I''m aware of the problem if I change the cells of the 1st column of the grid but that''s not important now)
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
if(e.Style.Text == "v")
int col = e.ColIndex;
int row = e.RowIndex;
e.Style.BackColor = Color.Blue; /* this one works*/
gridDataBoundGrid1[row, col-1].BackColor = Color.Red; /* this does not work*/
does anyone have an idea why this isn''t working as I want???
(the examples on syncfusion''s site are on: http://www.syncfusion.com/support/EvaluationCenter/viewsource.aspx?lang=csharp&id=157
and the full project can be downloaded from:
ADAdministrator Syncfusion Team March 16, 2005 09:47 AM
In PrepareViewStyleInfo, when e.RowIndex, e.ColIndex point to teh cell you might want to color, then you should do your check at that point, and set e.Style.backColor if the check indicates it should be colored.
//to make sure the whole row is refreshed as needed, in form.load, set
this.grid.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow;
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender,
//color col 2 if col 1 is "v"
if(e.ColIndex == 2 && e.RowIndex > 0)
string s = this.gridDataBoundGrid1[e.RowIndex, 1].Text;
if(s == "v")
e.Style.BackColor = Color.Red;