How do I change font size on the DataGridView?
-
Note your probably also want to change the row height if you are increasing the font size stackoverflow.com/questions/3370236/… – Matthew Lock Dec 20 '16 at 4:20
private void UpdateFont()
{
//Change cell font
foreach(DataGridViewColumn c in dgAssets.Columns)
{
c.DefaultCellStyle.Font = new Font("Arial", 8.5F, GraphicsUnit.Pixel);
}
}
-
How do I find out which font is used by default? Say I just want to change the existing font a bit. I get a
NullReferenceException
though. – Hamish Grubijan Apr 5 '12 at 18:30 -
You can get a reference to the font used in the DataGridView with DataGridView.DefaultCellStyle.Font – Maxence Apr 24 '14 at 18:31
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.
-
3
The straight forward approach:
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);
I think it's easiest:
First set any Label as you like (Italic, Bold, Size etc.) And:
yourDataGridView.Font = anyLabel.Font;
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.
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
For changing particular single column font size use following statement
DataGridView.Columns[1].DefaultCellStyle.Font = new Font("Verdana", 16, FontStyle.Bold);
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
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.
-
1leora questions was about changing font not removing the RowsDefaultCellStyle – Amir978 Jan 9 '12 at 5:51
' 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