Get width of DataGridView Column When AutoGenerateColumns = true And It added dynomically?

Posted by n H on Stack Overflow See other posts from Stack Overflow or by n H
Published on 2013-07-02T05:02:38Z Indexed on 2013/07/02 5:05 UTC
Read the original article Hit count: 130

Filed under:
|

I want to get width of each column of DataGridView in codeBehinde after setting DataSource and before showing it to user:

 DataGridView dgv = new DataGridView();
 dgv.AutoGenerateColumns = true;
 dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
 dgv.AutoSize = true;
 dgv.DataSource = dc.Branches.ToList();
 this.Controls.Add(dgv);

 //How to get Width of each Column Here??
 var ColCount = dgv.Columns.Count; //return 0 ??

© Stack Overflow or respective owner

Related posts about c#

Related posts about datagridview