?
Solved

Change the text color in a datagridviewtextboxcell

Posted on 2009-04-15
4
Medium Priority
?
427 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:ddepuemd
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Cakinci earned 1000 total points
ID: 24154909
You have to override the datagridViewTextBoxCell Paint method. I never tried by myself but there is someone tried here in this link with the full code; I analyzed and seems logical.
http://www.devx.com/codemag/Article/35186/1954

Hope this information will help you.
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1000 total points
ID: 24154912
I'm not sure if these can help you further in your research...

Datagridview multi color cell text
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22477105.html

Changing text color in a DataGrid using itemRenderers
http://butterfliesandbugs.wordpress.com/2007/06/14/changing-text-color-in-a-datagrid-using-itemrenderers/
0
 

Author Comment

by:ddepuemd
ID: 24160355
I've tried all of those suggestions with no success at all.
0
 

Author Comment

by:ddepuemd
ID: 24180703
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!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question