Link to home
Start Free TrialLog in
Avatar of ddepuemd
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
Avatar of Cakinci
Cakinci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ddepuemd
ddepuemd

ASKER

I've tried all of those suggestions with no success at all.
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.ColumnIndex).Value) Then
                        Dim value As Integer = Val(dgvMainGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
                        If value < 0 Then
                            dgvMainGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.Red
                            dgvMainGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.White
                        End If
                    End If
                End If

Thanks for the help!