Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to give different font size to different columns in a datagridview(default cell style has been already set in properties). but I need different font size for different column.

thanks in advance
Posted

1 solution

I assume you need this done in code?

This may not help a lot: you may have to tweak the row heights as well, as altering the cell font size does not affect that.
C#
private void SetColumns()
    {
    float current = 5.0F;
    foreach (DataGridViewColumn col in myDataGridView.Columns)
        {
        col.DefaultCellStyle.Font = new Font("Verdana", current);
        current += 5.0F;
        }
    }
 
Share this answer
 
Comments
[no name] 27-Oct-11 13:08pm    
I want to use the code in dataGridView1_CellFormatting event handler.because this will retain the required font size and color.I used the following line for that porpose

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if ((this.dataGridView1.Columns[e.ColumnIndex].Name == "RECTIFICATIONS") && (e.RowIndex > -1))
{

DataGridViewCellStyle cs = new DataGridViewCellStyle();
cs.ForeColor = Color.Red;
cs.Font = new System.Drawing.Font("Arial", 10F);
dataGridView1.Rows[e.RowIndex].Cells["RECTIFICATIONS"].Style = cs;


} }
but this code make the datagridview column shake vigourously. what approach I should take in this matter
OriginalGriff 27-Oct-11 14:18pm    
I don't know - I have never tried that - have you considered hiding the DGV while you play with it's settings?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900