write with color in datagridview

  • Thread starter Thread starter JO
  • Start date Start date
J

JO

hello,
how can i make to write my text with a color in my datagridview ?

for example, i want a text in blue if it ok for one condition, green
for an another condition....

thx
 
Set up multiple DataGridViewCellStyles and then
apply it to the cells you want to change.

Dim MakeItRed as New DataGridViewCellStyle()
MakeItRed.ForeColor = Color.Red

You can do a whole column:
thisGrid.Columns("price").DefaultCellStyle = MakeItRed

To apply this to a cell, you have to access the cell
through the row.

For Each row1 As DataGridViewRow In thisGrid.Rows
If row1.Cells("price").Value IsNot DBNull.Value Then
If CType(row1.Cells("price").Value, Decimal) > 5 Then
row1.Cells("price").Style = MakeItRed
Else
row1.Cells("price").Style = MakeItBlue
End If
End If
Next

Hope this helps.
Robin S.
 
RobinS a émis l'idée suivante :
Set up multiple DataGridViewCellStyles and then
apply it to the cells you want to change.

Dim MakeItRed as New DataGridViewCellStyle()
MakeItRed.ForeColor = Color.Red

You can do a whole column:
thisGrid.Columns("price").DefaultCellStyle = MakeItRed

To apply this to a cell, you have to access the cell
through the row.

For Each row1 As DataGridViewRow In thisGrid.Rows
If row1.Cells("price").Value IsNot DBNull.Value Then
If CType(row1.Cells("price").Value, Decimal) > 5 Then
row1.Cells("price").Style = MakeItRed
Else
row1.Cells("price").Style = MakeItBlue
End If
End If
Next

Hope this helps.
Robin S.

thx very much
 
Back
Top