datagrid fomat issues

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

Hi,

Just wondering if anybody knows how to get the column headings in a datagrid
to wrap i.e so I can see all the text without sizing column, also is there a
way to autofit columns to the data ?

Thanks

Neil
 
Neil said:
Hi,

Just wondering if anybody knows how to get the column headings in a datagrid
to wrap i.e so I can see all the text without sizing column, also is there a
way to autofit columns to the data ?

Examples abound. If gs is a datagridcolumnstyle, try something like:

// to get size, need reference to UI object
StringFormat sf = new
StringFormat(StringFormat.GenericTypographic);
Graphics g = Graphics.FromHwnd(this.Handle);
SizeF size;

for(int i = 0; i < numRows; ++ i)
{
size = g.MeasureString((dt.Rows[col]).ToString(),
this.Font, 500, sf);
if(size.Width > width)
width = size.Width;
}

// sh is the header text
size = g.MeasureString(sh, this.HeaderFont, 500, sf);
if( size.Width > width ) width = size.Width;

width += 16; // growing room

g.Dispose();
gs.Width = width;
 
Back
Top