DataGridView AutoFit and Fill

前端 未结 10 656
孤独总比滥情好
孤独总比滥情好 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 08:05

    To build on AlfredBr's answer, if you hid some of your columns, you can use the following to auto-size all columns and then just have the last visible column fill the empty space:

    myDgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
    myDgv.Columns.GetLastColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.None).AutoSizeMode = 
        DataGridViewAutoSizeColumnMode.Fill;
    

提交回复
热议问题