J
Jörgen Ahrens
Hi All
VS 2005 SP1
I use a DataGridView to display some figures. I have a cellpainting event
that displays a couple of numbers in bold and other numbers in regular font
style. When i double click the Column devider it resizes the column so that
the regular formated columns fit in but not the bold formated columns.
What is te best workaround for this problem?
I tryed overwritting the ColumnDividerDoubleClick event:
private void gridEditColumn_ColumnDividerDoubleClick(object sender,
DataGridViewColumnDividerDoubleClickEventArgs e)
{
Font font = new Font(gridEditColumn.DefaultCellStyle.Font,
FontStyle.Bold);
Graphics g = gridEditColumn.CreateGraphics();
Size s;
int width = 0;
for (int i = 0; i < gridEditColumn.Rows.Count; i++)
{
s =
g.MeasureString(gridEditColumn.Rows.Cells[e.ColumnIndex].FormattedValue.ToString(),
font).ToSize();
if (width < s.Width)
{
width = s.Width;
}
}
gridEditColumn.Columns[e.ColumnIndex].Width = width;
e.Handled = true;
}
but the width i get is still to small so that the bold value doesn't fit
in... i'm scared to just add a couple of pixels to the width...or do i have
to do so?
is there a better way to do it?
thanks for your help.
jahrens
VS 2005 SP1
I use a DataGridView to display some figures. I have a cellpainting event
that displays a couple of numbers in bold and other numbers in regular font
style. When i double click the Column devider it resizes the column so that
the regular formated columns fit in but not the bold formated columns.
What is te best workaround for this problem?
I tryed overwritting the ColumnDividerDoubleClick event:
private void gridEditColumn_ColumnDividerDoubleClick(object sender,
DataGridViewColumnDividerDoubleClickEventArgs e)
{
Font font = new Font(gridEditColumn.DefaultCellStyle.Font,
FontStyle.Bold);
Graphics g = gridEditColumn.CreateGraphics();
Size s;
int width = 0;
for (int i = 0; i < gridEditColumn.Rows.Count; i++)
{
s =
g.MeasureString(gridEditColumn.Rows.Cells[e.ColumnIndex].FormattedValue.ToString(),
font).ToSize();
if (width < s.Width)
{
width = s.Width;
}
}
gridEditColumn.Columns[e.ColumnIndex].Width = width;
e.Handled = true;
}
but the width i get is still to small so that the bold value doesn't fit
in... i'm scared to just add a couple of pixels to the width...or do i have
to do so?
is there a better way to do it?
thanks for your help.
jahrens