FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calculate the width of ListView colums

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
greatgatsby



Joined: 06 Aug 2010
Posts: 10
Location: South Africa (Cape Town)

PostPosted: Fri Nov 04, 2011 9:19 am    Post subject: Calculate the width of ListView colums Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group