使用FillWeight
后我想要DataGridView列的宽度。这是我的代码(C#,VS2015)。我试图将textBox宽度设置为与dgv列宽相同。代码的最后一行是我关注的问题:
//Initialise dgv
//Set column widths for visual appeal
dgvPRD.Columns["INAME"].FillWeight = 200;
dgvPRD.Columns["IBATCH"].FillWeight = 150;
dgvPRD.Columns["DPQTY"].FillWeight = 100;
dgvPRD.Columns["IPUOMNAME"].FillWeight = 50;
dgvPRD.Columns["IQTY"].FillWeight = 100;
dgvPRD.Columns["INOTE"].FillWeight = 300;
//Initialise textBox locations and sizes
txtINAME.Left = this.Left + 41; //41 is the RowHeadersWidth of the dgv
txtINAME.Top = dgvPRD.ColumnHeadersHeight;
txtINAME.Width = dgvPRD.Columns["INAME"].Width; --> not working (it gives the original column width, before `FillWeight`)