Repost: Dynamically Size List Box Height

  • Thread starter Thread starter Joe Keller
  • Start date Start date
J

Joe Keller

Reposting - no response first go around...

What's the best way to dynamically size the height of a list box based on
the number of items contained in the list?

In my application I dynamically create a list box that could have from 1 to
N number of items added to the list. If I have enough room on the form, I
want to ensure that the height of the list box is tall enough such that I
can see each item in the list without scrolling.

I'm running into a roadblock, however, in that I cannot find an accurate way
to gauge how to set the height on the list box (based on the number of items
in the list) such that it's at just the right height - not too short so that
scroll bars appear and not too tall so that I have empty space on the bottom
of the list.

Has anyone come across this issue and solved it already? I'd appreciate any
pointers!

Thanks,

Joe
 
You can send a message LB_GETITEMHEIGHT(0, 0) to a listbox to query the item
height. Then multiply it by the item count and resize yout listbox
 
Thanks - will do!

Joe

Alex Feinman said:
You can send a message LB_GETITEMHEIGHT(0, 0) to a listbox to query the item
height. Then multiply it by the item count and resize yout listbox
 
Back
Top