datagirdview跟据内容自动适应单元格大小
public static void AutoWidth(DataGridView dgv, DataTable dt)
{
int i = 0;
int w_Count = 0;
int w = 0;
int width = dgv.Width;
int avgWidth = width / dt.Columns.Count;//求出每一列的header宽度
dgv.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
dgv.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True;//数据溢出换行,根据内容大小自动换行
for (; i < dgv.Columns.Count; i++)
{
dgv.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells);
}
}