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

Individual cell colors in GridDataBoundGrid

How do I change the background color the current cell in the GridDataBoundGrid when a specific event happens? The PrepareViewStyleInfo doesn''t work well for this. thanks

2 Replies

AD Administrator Syncfusion Team July 11, 2006 06:32 PM UTC

Hi Susie, By default, DataBoundGrid doesn''t store any style info properties. You can not set any cell or row specific properties for the DataBoundGrid other than the CellValue.You need to handle the PrepareViewStyleInfo (or Model.QueryCellInfo) Event to do this.Through this event you can set the style properties for the grid. To set the BackColor for a currentcell, you check for the e.RowIndex/e.ColIndex, if that points to the row you desired, set the e.Style.BackColor for it. Here is some code snippet. //PrepareViewStyleInfo or Model.QueryCellInfo event GridCurrentCell cc = this.grid.CurrentCell; if( e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex ) { e.Style.BackColor = Color.Red; } KnowledgeBase Articles: QueryCellInfo event : http://www.syncfusion.com/Support/article.aspx?id=10351 PrepareViewStyleInfo event :http://www.syncfusion.com/Support/article.aspx?id=560 Please let me know if this helps. Regards, Haneef


SS Susie Smith July 11, 2006 06:58 PM UTC

>Hi Susie, > >By default, DataBoundGrid doesn''t store any style info properties. You can not set any cell or row specific properties for the DataBoundGrid other than the CellValue.You need to handle the PrepareViewStyleInfo (or Model.QueryCellInfo) Event to do this.Through this event you can set the style properties for the grid. > >To set the BackColor for a currentcell, you check for the e.RowIndex/e.ColIndex, if that points to the row you desired, set the e.Style.BackColor for it. Here is some code snippet. > >//PrepareViewStyleInfo or Model.QueryCellInfo event >GridCurrentCell cc = this.grid.CurrentCell; >if( e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex ) >{ > e.Style.BackColor = Color.Red; >} > >KnowledgeBase Articles: >QueryCellInfo event : http://www.syncfusion.com/Support/article.aspx?id=10351 >PrepareViewStyleInfo event :http://www.syncfusion.com/Support/article.aspx?id=560 > >Please let me know if this helps. >Regards, >Haneef Ok I ended up turning the event on and off because I want the cell color to change under certain situations. thanks Susie

Loader.
Live Chat Icon For mobile
Up arrow icon