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.
Unfortunately, activation email could not send to your email. Please try again.

How do I change the Backcolor of a single cell in a GridDataBoundGrid?

 

In a GridDataBoundGrid, you cannot set cell specific properties like BackColor (other than CellValue or Text) using an indexer like this.gridDataBoundGrid[8,10].BackColor=Color.Red. 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 the cell you want to change, you set e.Style to the value you want.

C#

private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)

{

if(e.ColIndex == 2 && e.RowIndex == 2)

{

e.Style.BackColor = Color.Red;

}

}

VB

Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(sender As Object, e As GridPrepareViewStyleInfoEventArgs)

If e.ColIndex = 2 And e.RowIndex = 2 Then

e.Style.BackColor = Color.Red

End If

End Sub

Sample:

http://websamples.syncfusion.com/samples/kb/grid.windows/GDBGSingleCell/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
458 04/30/2011 07/10/2014 Windows Forms GridDataBoundGrid(Classic)
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.