DataGridView question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxleCBLLg==?=

    DataGridView question

    Hi all

    No matter how hard I try, I cannot force my DataGridView to use specific
    font in column headers: it seems to be always the same as container's font
    (which is form in my case).
    I set styles:
    ColumnHeadersDe faultCellStyle
    DefaultCellStyl e

    and even
    AlternatingRows DefaultCellStyl e
    and
    RowsDefaultCell Style

    making sure thay all use specific font /size, but at run time column headers
    appear in sans serif 10pt, which is the same as form's font.

    What's wrong?

    Is it because I am assigning DataSource on the fly without adding columns at
    design time?

    Thank you
  • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

    #2
    RE: DataGridView question

    This works for me. I made a form and dragged a datagridview on and put this
    in the code:

    private void frmTest_Load(ob ject sender, EventArgs e)
    {

    DataTable table = new DataTable("My Table");
    table.Columns.A dd(new DataColumn("Col 1", typeof(string)) );
    table.Columns.A dd(new DataColumn("Col 2", typeof(string)) );
    table.Columns.A dd(new DataColumn("Col 3", typeof(string)) );
    table.Columns.A dd(new DataColumn("Col 4", typeof(string)) );

    dataGridView1.C olumnAdded += new
    DataGridViewCol umnEventHandler (dataGridView1_ ColumnAdded);
    dataGridView1.D ataSource = table;



    }

    void dataGridView1_C olumnAdded(obje ct sender, DataGridViewCol umnEventArgs e)
    {
    e.Column.Header Cell.Style = new DataGridViewCel lStyle();
    e.Column.Header Cell.Style.Font = new System.Drawing. Font("Arial", 14,
    FontStyle.Under line);

    }

    --
    Ciaran O''Donnell
    try{ Life(); } catch (TooDifficultException) { throw Toys(); }



    "Alex K." wrote:
    Hi all
    >
    No matter how hard I try, I cannot force my DataGridView to use specific
    font in column headers: it seems to be always the same as container's font
    (which is form in my case).
    I set styles:
    ColumnHeadersDe faultCellStyle
    DefaultCellStyl e
    >
    and even
    AlternatingRows DefaultCellStyl e
    and
    RowsDefaultCell Style
    >
    making sure thay all use specific font /size, but at run time column headers
    appear in sans serif 10pt, which is the same as form's font.
    >
    What's wrong?
    >
    Is it because I am assigning DataSource on the fly without adding columns at
    design time?
    >
    Thank you

    Comment

    Working...