获取DataGridView列的宽度当AutoGenerateColumns = true(动态添加)时?

时间:2013-07-02 05:02:38

标签: c# datagridview

我希望在设置DataSource之后以及在向用户显示之前获取codeBehind中每列DataGridView的宽度:

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 ??

0 个答案:

没有答案