Is there any way to set the maximum size of a ListBox (by pixels)? I know that there is a SetMaxSize but it is not enforced.

Recommended Answers

All 7 Replies

Put the ListBox in a sizer.

It is already in a sizer. The ListBox is empty to begin with. Then from user input, I add a list of numbers, which does not change the size. However, if the Frame is resized the ListBox become too big, and shrinks the Panels around it. SetMaxSize doesn't seem do anything to stop it from growing.

At this point you have to show us your code, so we can see how you configured the sizer.

Here is the code in the immediate panel.

self.record_numbers = wx.ListBox(self, -1, choices=[], 
                                         style=wx.LB_SINGLE|wx.LB_NEEDED_SB)
self.record_numbers.SetMinSize((50, -1))
self.record_numbers.SetMaxSize((75, -1))

self.sizer_staticbox = wx.StaticBox(
            self, -1, 'Search | Search for "THE SEARCH STRING" retrieved X records')

self.sizer = wx.StaticBoxSizer(self.sizer_staticbox, wx.HORIZONTAL)

self.rlist_sizer = wx.BoxSizer(wx.VERTICAL)
self.rlist_sizer.Add(self.record_numbers, 0, wx.ALL|wx.EXPAND, 3)

self.sizer.AddMany([(self.buttons_sizer, 0, wx.ALL|wx.ALIGN_CENTER, 3),
                            (self.rlist_sizer, 1, wx.ALL, 3),
                            (self.sc_buttons_sizer, 0, wx.ALL|wx.ALIGN_CENTER, 3)])

I'm confused. If it doesn't have the method, then how is it that wx.ListBox.SetMaxSize() is valid code?

I know this is an old thread but I must make this clear. ListBox itself doesn't have a method named SetMaxSize, but it is a descendant of Window so the method is inherited.

I'm still looking for the answer that you asked, so if you have found it already please post :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.