ddepuemd
asked on
Change the text color in a datagridviewtextboxcell
How can I change the color of the text in a cell according to it's position within the cell? In other words, I want to have the first four characters be light blue and the last four to be light green, all within the same cell. I've tried to split the text, which is easy, and then use graphics to drawstring with different colored brushes, but it doesn't seem to work. Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a way to do this in the paint method of the grid:
If e.ColumnIndex = 10 Then
If Not IsDBNull(dgvMainGrid.Rows( e.RowIndex ).Cells(e. ColumnInde x).Value) Then
Dim value As Integer = Val(dgvMainGrid.Rows(e.Row Index).Cel ls(e.Colum nIndex).Va lue)
If value < 0 Then
dgvMainGrid.Rows(e.RowInde x).Cells(e .ColumnInd ex).Style. BackColor = Color.Red
dgvMainGrid.Rows(e.RowInde x).Cells(e .ColumnInd ex).Style. ForeColor = Color.White
End If
End If
End If
Thanks for the help!
If e.ColumnIndex = 10 Then
If Not IsDBNull(dgvMainGrid.Rows(
Dim value As Integer = Val(dgvMainGrid.Rows(e.Row
If value < 0 Then
dgvMainGrid.Rows(e.RowInde
dgvMainGrid.Rows(e.RowInde
End If
End If
End If
Thanks for the help!
ASKER