使用FillWeight后如何获取datagridview列的绝对宽度?

时间:2018-06-02 16:17:12

标签: c# visual-studio-2015 datagridview

使用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`)

0 个答案:

没有答案