我将WinForm datagridview列的宽度设置为140,我正在检查宽度,它是100.网格宽度足以使所有列更宽。为什么列不接受140值?是否有控制最大宽度的设置?
MyGrid.Columns["Name"].Width = 140;
int i = MyGrid.Columns["Name"].Width; //why is i = 100?
答案 0 :(得分:3)
检查MyGrid.Columns["Name"].AutoSizeMode
,将其设置为DataGridViewAutoSizeColumnMode.NotSet
MyGrid.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
答案 1 :(得分:1)
da.Fill(dtable);
dgvCategory.DataSource = dtable;
dgvCategory.Columns["Category"].AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
dgvCategory.Columns["Category"].Width=150;
dgvCategory.Columns["MainCat"].Width = 180;