StrataFrame Forum

Coloring a datagridview

http://forum.strataframe.net/Topic31293.aspx

By Thomas Holste - 7/24/2012

Hi There,

I am trying to color rows in a grid depending on a special value in a database field.

What I haven't yet figured out is how I can do this depending on a BO-Value and not a

cell-value.

For example: I have a datagridview with a BBS as datasource which is connected to a BO.

In this BO I have a field called "isdeleted" and I want to show all coresponding lrows with the forecolor set to red.

What I do now is the following: I have added an invisible column with this field to the datagridview and have a little sub which colors the rows:



Private Sub setgridcolor()

For I As Integer = 0 To kundengrid.Rows.Count - 1

   If kundengrid.Rows(I).Cells("IsDeleted").Value = "J" Then

      kundengrid.Rows(I).DefaultCellStyle.ForeColor = Color.Red

   End If

Next

End Sub



And then I call this sub in the paint-event of the datagridview.

Everything works fine but somehow it does not feel right and I would like to know how this can be done better?

Thanks in advance

Thomas