views:

232

answers:

2

I ve created columns of my datagrid using this,

   private void Receive_Load(object sender, System.EventArgs e)
    {
        dt.Columns.Add("Sender",typeof(string));
        dt.Columns.Add("Time",typeof(string));
        dt.Columns.Add("Message",typeof(string));
    }
  • How can i dynamically assign a column width to a winforms datagrid?
A: 

Here's a suggestion: If you know the length of your fields you can multiply their length by a constant value (max character width for example) to produce a dynamic width.

Beatles1692
A: 

I think you are searching for something line

dt.Columns["ColumnName"].Width = 75;

I Hope it help you.

In addition, you can set the AutoSizeMode of the column to obtain different behaviours automatically. For example, if you set it to ColumnHeader, then the cell width will be set to the best fit for showing the header text. You can get more info in this Link.

Jonathan