SizeF tmpSize = new SizeF(); Font tmpFont; float tmpWidth; TheDataGridViewWidth = 0; for (int i = 0; i < TheDataGridView.Columns.Count; i++) { tmpFont = TheDataGridView.ColumnHeadersDefaultCellStyle.Font; if (tmpFont == null) // If there is no special HeaderFont style, then use the default DataGridView font style tmpFont = TheDataGridView.DefaultCellStyle.Font; tmpSize = g.MeasureString(TheDataGridView.Columns[i].HeaderText, tmpFont); tmpWidth = tmpSize.Width; RowHeaderHeight = tmpSize.Height; for (int j = 0; j < TheDataGridView.Rows.Count; j++) { tmpFont = TheDataGridView.Rows[j].DefaultCellStyle.Font; if (tmpFont == null) // If the there is no special font style of the CurrentRow, then use the default one associated with the DataGridView control tmpFont = TheDataGridView.DefaultCellStyle.Font; tmpSize = g.MeasureString("Anything", tmpFont); RowsHeight.Add(tmpSize.Height); tmpSize = g.MeasureString(TheDataGridView.Rows[j].Cells[i].EditedFormattedValue.ToString(), tmpFont); if (tmpSize.Width > tmpWidth) tmpWidth = tmpSize.Width; } if (TheDataGridView.Columns[i].Visible) TheDataGridViewWidth += tmpWidth; ColumnsWidth.Add(tmpWidth); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)