datagrid fomat issues

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
 
S

Steve Alpert

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top