greatgatsby
Joined: 06 Aug 2010 Posts: 10 Location: South Africa (Cape Town)
|
Posted: Fri Nov 04, 2011 9:19 am Post subject: Calculate the width of ListView colums |
|
|
I am trying to calculate the width of ListView colums to auto-adjust to the size of the widest text in the column before showing the Form.
I originally thought I can use the getAutoScaleSize() or getAutoScaleSize(Font f) methods in the Control class (ListView's parent). These functions return a Size object, which contain a width (and length) member.
But the items in ListView are held in a ListViewItemCollection (which holds ListViewItems). None of these types are derived from Control, so you cannot call getAutoScaleSize(..) on the items.
The only other alternative I could come up with was to use the Win API GetTextExtentPoint32 function, but I noticed that Graphic's measureText(Dstring text, Font font) method (that uses GetTextExtentPoint32) has been commented out (without any comment as to the reason why).
I now wonder if there is a problem doing it that way. I will anyway try it, but wondered if anyone has any tips/advice?
regards,
greatgatsby |
|