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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top