Dynamic window sizing with a wxListCtrl

Hi folks,

I'm writing an app that has a frame containing a panel containing a
wxListCtrl and OK/Cancel buttons. When it displays, I'd like the height of
the frame to size dynamically to show all the elements in the list without
having to scroll. I can roughly figure out how high the wxListCtrl should
be by calling wxListCtrl::GetCharHeight(), then multiplying it by the number
if items in the list. But I can't figure out what to do with that number to
appropriately size the frame (and its child windows). I've tried various
combinations of wxWindow::SetSize(size)on both the frame obj and the
wxListCtrl obj, but can't get it to look right.

Two questions:

1. Is there a better way to determine the required height of the wxListCtrl
than the technique I'm using?

2. What do I do with the height value (once I get it) to actually affect
the size of the window?

Thanks.

Paul Gardella

Paul Gardella wrote:

Hi folks,

I'm writing an app that has a frame containing a panel containing a
wxListCtrl and OK/Cancel buttons. When it displays, I'd like the height of
the frame to size dynamically to show all the elements in the list without
having to scroll. I can roughly figure out how high the wxListCtrl should
be by calling wxListCtrl::GetCharHeight(), then multiplying it by the number
if items in the list. But I can't figure out what to do with that number to
appropriately size the frame (and its child windows). I've tried various
combinations of wxWindow::SetSize(size)on both the frame obj and the
wxListCtrl obj, but can't get it to look right.

Two questions:

1. Is there a better way to determine the required height of the wxListCtrl
than the technique I'm using?

Probably not. If wxListCtrl had an implementation for GetBestSize then you could use that, but I don't think it does.

2. What do I do with the height value (once I get it) to actually affect
the size of the window?

If you are doing your layout with sizers then you can just tell the sizer what the minimum size of the listctrl is and then use Fit to resize the containing windows as needed.

If you want to do it more manually then one you figure out how big the panel should be then call the Frame's SetClientSize to be that big.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!