Is it possible to have a multicolored text in the grid cells ? So I can do this :
abcdefgd
I don't want it to have all the bells and whistles of the rich text editor , in fact it will not be an editable cell. I just want the text to appear in the different colors according to my own logic.
I am also inside the Infragistics UltraWinGrid which probably does not matter, but just in case it makes a difference.
Thanks
vlad shcloverPosted Apr 28, 2008, 1:38 PM
Thanks
Vlad
Niradhip ChakrabortyPosted Apr 25, 2008, 5:40 PM
STEP 1:
You'll need to create a custom control that does the multicolor text.
It is probably easiest inherited from Label (I assume you're not going to have users inputting text into the cells).
Here is a very basic implementation. Obviously, you'd need to beef up this class with some more useful functionality,
but it shows you how to draw the multicolor label:
Public Class myMultiColorLabel
Inherits Label
Private ColorStrings As New Dictionary(Of String, Color)
Public Sub New()
MyBase.AutoSize = False
Me.ColorStrings.Add("WordOne ", Color.Red)
Me.ColorStrings.Add("WordTwo ", Color.Blue)
Me.ColorStrings.Add("WordThree ", Color.Green)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim graphics As Graphics = e.Graphics
Dim runningWidthTotal As Double = 0 'keep track of where to place each character
For Each d As KeyValuePair(Of String, Color) In Me.ColorStrings
graphics.DrawString(d.Key, MyBase.Font, New SolidBrush(d.Value), _
runningWidthTotal, 0)
runningWidthTotal += graphics.MeasureString(d.Key, MyBase.Font).Width
Next
MyBase.Width = runningWidthTotal
End Sub
End Class
STEP 2:
You'll need to create custom DataGridViewColumn and DataGridViewCell types to
host the control you create in the first step.