How do you automatically resize columns in a DataGridView control AND allow the user to resize the columns on that same grid?

后端 未结 24 3060
孤城傲影
孤城傲影 2020-11-29 18:03

I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF).

My goal is to display a grid that neatly fills all available width with cells - i.e. no un

24条回答
  •  日久生厌
    2020-11-29 18:32

    If I understood the question correctly there should be an easier way to accomplish what you need. Call dgvSomeDataGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

    That should do the trick. However, there is one pitfall as you cannot simply call this method directly after populating your DataGridView control. Instead you will have to add an EventHandler for the VisibleChanged event and call the method in there.

提交回复
热议问题