how to get minimum width of a column in a DBGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

If you doubleclick on a dbgrid title separator the column automticly resize
to his minumum width. How to do this in code ?
 
Wilfried said:
Hi,

If you doubleclick on a dbgrid title separator the column automticly resize
to his minumum width. How to do this in code ?

Hi,

what would you like to do in code? Double-click on column or resize
column? If you want to resize the col. to its minimum, you can go
through all values in this col. and use the Graphics.MeasureString
method to determin the size of the current string in col and get the
minimum of all values. This is the min. size of the col. The "size" of
the string depends on the used font. So you need also to get the used
font of the col.

string measureString = "Measure String";
Font stringFont = new Font("Arial", 16);

SizeF stringSize = new SizeF();
stringSize = e.Graphics.MeasureString(measureString,
stringFont);


With regards,

Andy
 

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

Back
Top