Reputation: 196459
How do I change font size on the DataGridView?
Upvotes: 51
Views: 178318
Reputation: 1090
I adding the note that when you change font size you might also need to review the row height:
dgv.DefaultCellStyle.Font = new Font("Tahoma", 15);
dgv.RowTemplate.Height = 30;
and sometimes adjusting the decimal places if relevant for your case:
dgv.Columns[i].DefaultCellStyle.Format = "N2";
Upvotes: 0
Reputation: 41
In DataGridView, right click properties, In RowTemplate > DefaultCellStyle change the Font Size, It worked for me
Upvotes: 2
Reputation: 850
I think it's easiest:
First set any Label as you like (Italic, Bold, Size etc.) And:
yourDataGridView.Font = anyLabel.Font;
Upvotes: 5
Reputation: 2860
For changing particular single column font size use following statement
DataGridView.Columns[1].DefaultCellStyle.Font = new Font("Verdana", 16, FontStyle.Bold);
Upvotes: 6
Reputation: 29
1st Step: Go to the form where datagridview is added
2nd step: click on the datagridview at the top right side there will be displayed a small button of like play icon or arrow to edit the datagridview.
3rd step: click on that button and select edit columns now click the attributes you want to increase font size.
4th step: on the right side of the property menu the first on the list column named defaultcellstyle click on its property a new window will open to change the font and font size.
Upvotes: 2
Reputation: 4905
The straight forward approach:
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);
Upvotes: 25
Reputation: 61
I too experienced same problem in the DataGridView but figured out that the DefaultCell style was inheriting the font of the groupbox (Datagrid is placed in groupbox). So changing the font of the groupbox changed the DefaultCellStyle too.
Regards
Upvotes: 5
Reputation: 1
' Cell style
With .DefaultCellStyle
.BackColor = Color.Black
.ForeColor = Color.White
.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.0!,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
.Alignment = DataGridViewContentAlignment.MiddleRight
End With
Upvotes: 0
Reputation: 1
Go to designer.cs file of the form in which you have the grid view and comment the following line: - //this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
if you are using vs 2008 or .net framework 3.5 as it will be by default applied to alternating rows.
Upvotes: 0
Reputation: 3418
In winform datagrid, right click to view its properties. It has a property called DefaultCellStyle. Click the ellipsis on DefaultCellStyle, then it will present Cell Style Builder window which has the option to change the font size.
Its easy.
Upvotes: 82
Reputation: 1062
private void UpdateFont()
{
//Change cell font
foreach(DataGridViewColumn c in dgAssets.Columns)
{
c.DefaultCellStyle.Font = new Font("Arial", 8.5F, GraphicsUnit.Pixel);
}
}
Upvotes: 56
Reputation: 41919
Use the Font-property on the gridview. See MSDN for details and samples:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.font.aspx
Upvotes: 1