locked
how to change font of a specific column header in datagridview c#.net RRS feed

  • Question

  • hi dears.

    i have a datagridview with some columns. i want to change font of a first column header. how can i do it?

    Wednesday, July 13, 2011 7:32 AM

Answers

  • Hi

    I think this is what you are looking for.  

      DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.Font = new Font(this.Font, FontStyle.Bold);
    dataGridView1.Columns[0].HeaderCell.Style= style;
    

    Change the first header of dataGridview. You may change the index for specific header.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie Luo Monday, July 25, 2011 7:42 AM
    Monday, July 18, 2011 7:03 AM

All replies

  • You can do this by in data grid view column added event!

    if (e.Column.HeaderText == Your column header text)
                {

    DataGridViewCellStyle style = new DataGridViewCellStyle();
                    style.Alignment =
                        DataGridViewContentAlignment.MiddleCenter;
                    style.ForeColor = Color.IndianRed;
                    style.BackColor = Color.Ivory;


                    e.Column.HeaderCell.Style = style;

    }


    Wednesday, July 13, 2011 7:47 AM
  • Hello

    Please use this code

    For Column Header

    this.dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font(this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);

    For Single Header Column

    this.dataGridView1.Columns[0].HeaderCell.Style.Font = new Font(this.Font, FontStyle.Bold);

    For Column

    this.dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(this.Font, FontStyle.Bold);

    Thanks


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.

    Wednesday, July 13, 2011 8:40 AM
  • Hello

    Please use this code

    For Column Header

    this.dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font(this.dataGridView1.ColumnHeadersDefaultCellStyle.Font, FontStyle.Bold);

    For Column

    this.dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(this.Font, FontStyle.Bold);

    Thanks


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    hi . but i want to change specific header font not all headers font.
    Monday, July 18, 2011 5:28 AM
  • Hi

    I think this is what you are looking for.  

      DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.Font = new Font(this.Font, FontStyle.Bold);
    dataGridView1.Columns[0].HeaderCell.Style= style;
    

    Change the first header of dataGridview. You may change the index for specific header.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie Luo Monday, July 25, 2011 7:42 AM
    Monday, July 18, 2011 7:03 AM