R
Rainer Queck
Hello NG,
I am trying to adjust the column width of a DataGridView to the Text in its
column header.
To do this I am using the Graphics.MeasureString method. Unfortunatly I
alway get a too short string width.
What is it I am doing wrong?
Here the code I am using:
private void MinimizeDgvColumns(DataGridView dgv)
{
using (Graphics g = dgv.CreateGraphics())
{
foreach (DataGridViewColumn c in dgv.Columns)
{
string s = c.HeaderCell.Value.ToString();
c.Width = (int)graphics.MeasureString(s,
dgv.ColumnHeadersDefaultCellStyle.Font).Width;
}
}
}
Regards
Rainer Queck
I am trying to adjust the column width of a DataGridView to the Text in its
column header.
To do this I am using the Graphics.MeasureString method. Unfortunatly I
alway get a too short string width.
What is it I am doing wrong?
Here the code I am using:
private void MinimizeDgvColumns(DataGridView dgv)
{
using (Graphics g = dgv.CreateGraphics())
{
foreach (DataGridViewColumn c in dgv.Columns)
{
string s = c.HeaderCell.Value.ToString();
c.Width = (int)graphics.MeasureString(s,
dgv.ColumnHeadersDefaultCellStyle.Font).Width;
}
}
}
Regards
Rainer Queck