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

后端 未结 24 3074
孤城傲影
孤城傲影 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:44

    After adding the data to the grid add the following code which will adjust the column according to the length of data in each cell

    dataGrid1.AutoResizeColumns();            
    dataGrid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
    

    Here is the Result

    enter image description here

提交回复
热议问题