Winforms Datagrid Cell Text

G

Guest

Any ideas on how i can bold the text within a specific cell of a winforms
datagrid?i have used DataGridColumnStyle for an entire column,however
currently i need just the text of a specific cell to be bold?

Thanks
 
C

Chris, Master of All Things Insignificant

The way I did that is to override the Paint event of the DataGridColumnStyle
class. Couple things to note. There are several overloaded subs to deal
with, most just call a simpler version in the end. The example I have below
doesn't bold the font, it just changes the back/fore color but the brush is
what you need do the bold to I believe. Hope this helps.

Chris


Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _
ByVal Bounds As Rectangle, _
ByVal Source As CurrencyManager, _
ByVal RowNum As Integer, _
ByVal AlignToRight As Boolean)

Dim Text As String = GetText(GetColumnValueAtRow(Source, RowNum))
Dim DR As DataRow
DR = DirectCast(Source.Current, DataRowView).DataView.Item(RowNum).Row
If SomthingHappenedThen
Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor)
Dim ForeBrush As Brush = New SolidBrush(System.Drawing.Color.Salmon)
PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
ElseIf SomthingElseHappened Then
Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor)
Dim ForeBrush As Brush = New SolidBrush(System.Drawing.Color.RosyBrown)
PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight)
Else
PaintText(g, Bounds, Text, AlignToRight)
End If

End Sub
 

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

Top