DataGridView AutoFit and Fill

前端 未结 10 650
孤独总比滥情好
孤独总比滥情好 2020-12-02 07:37

I have 3 columns in my DataGridView. What I am trying to do is have the first 2 columns auto fit to the width of the content, and have the 3rd column fill the r

10条回答
  •  眼角桃花
    2020-12-02 07:58

    This is my favorite approach...

    _dataGrid.DataBindingComplete += (o, _) =>
        {
            var dataGridView = o as DataGridView;
            if (dataGridView != null)
            {
               dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
               dataGridView.Columns[dataGridView.ColumnCount-1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        };
    

提交回复
热议问题