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 01:22 PM

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 12:09 PM

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 12:57 AM

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 08:37 AM

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.
Live Chat Icon For mobile
Up arrow icon