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

Row BackColor

Hi, I want to set the backColor of a row in a databoundgrid based on the value of a particular column. In the PrepareViewStyleInfo handler, I check for the value of this particular column. Now how can I set the backcolor of the entire row? e.Style.BackColor in the eventhandler will only change the color for that particlar cell. Can I do something like grid.Model.RowStyles[row].BackColor = ... I am concerned that this might trigger endless recursive calls to PrepareViewStyleInfo. Thanks,

4 Replies

AD Administrator Syncfusion Team May 18, 2005 06:22 PM UTC

You will have to use PrepareviewStyleInfo to do this. Try code like this in PrepareviewStyleInfo to color the whole row.
if(e.ColIndex > 0 && e.RowIndex > 0)
{
   int colIndex = grid.Binder.NameToCOlIndex("TestValue");
   object testValue = grid[e.RowIndex, colIndex].Cellvalue;
   if(testValue == xyz)
      e.Style.BackColor = Color.Red;
}


AD Administrator Syncfusion Team November 8, 2005 05:09 PM UTC

Hi Clay, Could you tell me which event I should use for a GridGroupingControl. Thanks. Seb >You will have to use PrepareviewStyleInfo to do this. > >Try code like this in PrepareviewStyleInfo to color the whole row. >
>if(e.ColIndex > 0 && e.RowIndex > 0)
>{
>   int colIndex = grid.Binder.NameToCOlIndex("TestValue");
>   object testValue = grid[e.RowIndex, colIndex].Cellvalue;
>   if(testValue == xyz)
>      e.Style.BackColor = Color.Red;
>}
>


AD Administrator Syncfusion Team November 9, 2005 05:57 AM UTC

Hi Seb, You can handle the TableControlPrepareViewStyleInfo event. Here is some code snippet: private void TableControl_PrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e) { GridTableCellStyleInfo style = (GridTableCellStyleInfo) e.Inner.Style; if (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) { int colIndex=this.gridGroupingControl1.TableModel.NameToColIndex("Col1"); GridTableCellStyleInfo style1 = this.gridGroupingControl1.Table.GetTableCellStyle(e.Inner.RowIndex,colIndex); if(style1.Text =="row1 col1") e.Inner.Style.BackColor=Color.LightPink; } } Here is a sample. GC_BackColor.zip Let us know if this serves your purpose. Best Regards, Jeba


AD Administrator Syncfusion Team November 9, 2005 01:37 PM UTC

Thanks you very much Jeba .. this is exactly what I was looking for ... there is so many events that can be handled .. sometime I need a map or a guide :) Thanks also for being so quick to answer my question. Seb

Loader.
Up arrow icon