ListCtrl: setting height to maximum

Hello,

I'd like to allow a ListCtrl to take all the possible size in height but I don't manage to do it with a Sizer. Is there any other way around apart from setting a fixed size?

Thanks
Thomas Zuliani

Thomas Zuliani wrote:

Hello,

I'd like to allow a ListCtrl to take all the possible size in height but I don't manage to do it with a Sizer.

you should be able to do this with a sizer, by either setting "option" to > 0 or specifying the wx.EXPAND flag, depending on what kind of sizer it is. Make a small sample app that demonstrates your problem, post it here, and one of us will probably have a suggestion for you.

Sizer.Add(MyListControl, 1, wx.GROW)

Will set it to expand in both directions.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

you should be able to do this with a sizer, by either setting "option" to > 0 or specifying the wx.EXPAND flag, depending on what kind of sizer it is. Make a small sample app that demonstrates your problem, post it here, and one of us will probably have a suggestion for you.

Sizer.Add(MyListControl, 1, wx.GROW)

Will set it to expand in both directions.

Hello,
Thanks for your answer. This is exactly what I have written and I have still only four lines in my ListCtrl. I don't know how to have more than four lines.

This is my code :

self.globalSizer=wx.BoxSizer(wx.VERTICAL)
self.textSizer=wx.BoxSizer(wx.VERTICAL)
  
self.title=wx.StaticText(self, -1, "title")
self.textSizer.Add(self.title , 1, wx.ALIGN_LEFT)
self.textSizer.Add((5, 5), 0, wx.EXPAND)

self.nameText = wx.StaticText(self, -1, "Name")
self.textSizer.Add(self.nameText, 1, wx.ALIGN_LEFT)
self.NameTextCtrl = wx.TextCtrl(self,ID_NameTextCtrl, "", size = (500,25))
self.textSizer.Add(self.NameTextCtrl ,1,wx.EXPAND)
self.textSizer.Add((5, 5), 0, wx.EXPAND)

self.listSizer = wx.BoxSizer(wx.VERTICAL)
self.ListCtrl = WSLists.List(self, self.Number, Reader)
self.listSizer.Add(self.ListCtrl, 1, wx.GROW)
    
self.globalSizer.Add(self.textSizer, 0, wx.ALIGN_TOP)
self.globalSizer.Add(self.listSizer, 0, wx.EXPAND)

Thomas Zuliani

Thomas Zuliani wrote:

Sizer.Add(MyListControl, 1, wx.GROW)

Thanks for your answer. This is exactly what I have written and I have still only four lines in my ListCtrl. I don't know how to have more than four lines.

A) send a COMPLETE, WORKING, SMALL, sample. It's much more likely that we can figure out your problem, and test our proposed solution if you do. You also might find your problem yourself if you totally isolate the code.

Lucky for you, I decided to take the time and cut and paste your code into a simple sample I already had.

So about your code:

A) why so many sizers? you don't need them for every individual thing. For a simple layout of a bunch of stuff in a column, just use one vertical boxsizer.

B) don't put everything in "self", only those things that you will need access to from other methods. For instance, only put sizers in self if you will be adding or removing items dynamically. Same for StaticText controls, etc.

C) You don't need spacers here either, you can put space around objects in a sizer with assorted flags like wx.ALL, wx.TOP or wx.BOTTOM, and setting a spacer size:

globalSizer.Add(self.title , 0, wx.ALIGN_LEFT | wx.BOTTOM, 5)

puts the title window in, so it won't grow, aligned to the left, with a 5 pixel space at the bottom.

D) now to your actual question:

self.listSizer = wx.BoxSizer(wx.VERTICAL)
self.ListCtrl = WSLists.List(self, self.Number, Reader)
self.listSizer.Add(self.ListCtrl, 1, wx.GROW)

you've now added the ListCtrl to listSizer so that it will expand...

self.globalSizer.Add(self.listSizer, 0, wx.EXPAND)

however, you have added the ListSizer to global sizer, telling it NOT to expand. You don't need the ListSizer at all:

globalSizer.Add(self.ListCtrl, 1, wx.EXPAND)

will do fine.

I've enclosed a much trimmed down version, as a working app, tested on wxGTK 2.5.1

-Chris

SizerTest3.py (893 Bytes)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov