代码:
Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
或者设置DataGridView的AutoSizeColumnMode属性为AllCells