DataGridView column styles?

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
How to change a font size, font color of single column as well as the alignment of the column title? Thank you
 
Set these and other styles:
VB.NET:
DataGridView1.Columns(0).DefaultCellStyle.ForeColor = Color.Indigo
 
DataGridView1.EnableHeadersVisualStyles = False
DataGridView1.Columns(0).HeaderCell.Style.ForeColor = Color.Blue
 
"DataGridView1.Columns(0).DefaultCellStyle.ForeColor = Color.White" doesn't change the column cell color. May i know why? What about the alignment for both the column title and the cell? Thank you.
 
ForeColor set the text color. You can set all the other Style(s) for the HeaderCell too, ForeColor isn't the only style that is possibel set. Use the intellisense/help docs to browse.
 
Try This

VB.NET:
'Align the header & cell of the DataGridView
.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight

Best wishes!
 
Last edited:
DataGridView1.Columns(0).DefaultCellStyle.ForeColor = Color.Indigo doesn't change the font color, i think the reason is because it is a LinkColumn, i have tried the same for TextBoxColumn and it worked well. May i know how to set the color for LinkColumn? Thank you.
 
Last edited:
VB.NET:
Dim dgvLC As DataGridViewLinkColumn = DataGridView1.Columns(0)
dgvLC.LinkColor = Color.GreenYellow
 
I tried the following to change the fontstyle of a particular column but it didn't work. Thank you.

VB.NET:
[SIZE=2]Column.DefaultCellStyle.Font.Style = FontStyle.Bold
[/SIZE]
 
Most properties of Font object is readonly, you have to create a new Font instance and assign this to DefaultCellStyle.Font.
VB.NET:
Dim originalfont As Font = DataGridView1.Font
Dim newfont As New Font(originalfont, originalfont.Style Or FontStyle.Bold)
DataGridView1.Columns(0).DefaultCellStyle.Font = newfont
 
Back
Top