leora
leora

Reputation: 196459

WinForms DataGridView font size

How do I change font size on the DataGridView?

Upvotes: 51

Views: 178318

Answers (12)

Hannington Mambo
Hannington Mambo

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

Julio
Julio

Reputation: 41

In DataGridView, right click properties, In RowTemplate > DefaultCellStyle change the Font Size, It worked for me

Upvotes: 2

Mahmut K.
Mahmut K.

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

Niraj Trivedi
Niraj Trivedi

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

Sheraz Latif
Sheraz Latif

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

Ashraf Sada
Ashraf Sada

Reputation: 4905

The straight forward approach:

this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);

Upvotes: 25

CVKrishna
CVKrishna

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

Sylvio
Sylvio

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

sankalp korde
sankalp korde

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

Merin Nakarmi
Merin Nakarmi

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

psamwel
psamwel

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

Espo
Espo

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

Related Questions