代码:

Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

或者设置DataGridView的AutoSizeColumnMode属性为AllCells

相关文章: