473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Winforms Datagrid Cell Text

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
Nov 16 '05 #1
2 4662
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
"Vinny Vinn" <Vi*******@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
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

Nov 16 '05 #2
Thanks Chris,i was hoping there was a 'prettier' way then override the Paint
event

"Chris, Master of All Things Insignifican" wrote:
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
"Vinny Vinn" <Vi*******@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dav | last post by:
I have a Winform with a derived datagrid and a button that adds a row to the datagrid in its Click event. The button has a shortcut text "&New Row". When I enter a value in a datagrid cell and...
2
by: Nanda | last post by:
Hi all, while editing a datagrid cell, if i press Enter key focus goes to the next row, instead that i would like to have focus on next cell, how can i obtain this. Thanks & Regards, Nanda
1
by: VM | last post by:
Is it possible for the bound data in a web datagrid to be displayed in links? The grid will show the client's first name and last name and, when the user clicks on the first or last name, I want...
2
by: thomaz | last post by:
Hi; How can i store the content of one DataGrid cell in a String Variable? Thanks....
2
by: martin | last post by:
Hi, I am iterating through the dataitems in a datagrid and producing and xml document, If a particular cell in the datagrid has a textbox control or a datagrid control in it then I have no...
1
by: Tracey | last post by:
Hi, there My application requires to display multiline text in the cell of datagrid. I set the preferredheight of datagrid's tablsstyle, however, it is fixed. For text longer than that, the rest...
3
by: Mad Scientist Jr | last post by:
Can someone post a clear example of how to change the background color of an individual datagrid cell for a Windows desktop app? (preferably in vb.net) I found some code on how to do this when...
3
by: Jeff | last post by:
Help.. I have been using: string sId = ((System.Web.UI.WebControls.TextBox)e.Item.Cells.Controls).Text; To get the value of a cell in my datagrid. When I set the cell to read only, I get...
1
by: glenn | last post by:
Hi folks, I need to have two ddl's in one DataGrid cell. The first ddl has a list of company names and the second has a list of contact names that work in the company name that was selected in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.