Get width of DataGridView Column When AutoGenerateColumns = true And It added dynomically?
- by n H
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 ??