# ListBox's overlapping

**URL:** <https://www.ruby-forum.com/t/listboxs-overlapping/165211>\
**Category:** wxRuby\
**Created:** [April 10, 2009, 7:14am UTC](https://www.ruby-forum.com/t/listboxs-overlapping/165211 "2009-04-10T07:14:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 10, 2009, 7:14am UTC](https://www.ruby-forum.com/t/listboxs-overlapping/165211/1 "2009-04-10T07:14:35Z")

</div>

Guys,

I have a bug which I can’t solve at the moment. I tried various  
solutions, changing the sizers and lots of different ways, I still  
couldn’t fix it.

In my code, I have basically two ListBox in the same panel, one above  
the other.  
When the upper ListBox has too many elements, I have a nice scroll bar,  
and looks good. But When I resize my complete frame, it draws itself  
over the bottom one, and I can’t see it anymore. And the scroll bar is  
even gone, so I can’t even see all the elements.

Here is my code:

def initialize title, xml\_h  
super(nil, -1, title)  
@xml\_helper = xml\_h

global\_sizer = BoxSizer.new(VERTICAL)

@top\_p = Panel.new(self)  
@bottom\_p = Panel.new(self)

global\_sizer.add(@top\_p, 3, GROW|ALL, 2)  
global\_sizer.add(@bottom\_p, 1, GROW|ALL, 2)

top\_sizer = BoxSizer.new(HORIZONTAL)  
@m\_list = ListBox.new(@top\_p, -1, DEFAULT\_POSITION, DEFAULT\_SIZE,  
@xml\_helper.get\_magicians, LB\_SINGLE|LB\_SORT|DOUBLE\_BORDER)  
evt\_listbox @m\_list, :on\_magician\_pressed  
top\_sizer.add(@m\_list,1, GROW|ALL, 2)

@mc = MediaCtrl.new(@top\_p)  
evt\_media\_loaded @mc,:on\_media\_loaded  
top\_sizer.add(@mc, 3, GROW|ALL, 2)

```
right_sizer = GridSizer.new(2, 0, 2, 2)

```

right\_p = Panel.new(@top\_p)  
right\_p.fit  
right\_p.set\_sizer right\_sizer  
@v\_list = ListBox.new(right\_p, -1, DEFAULT\_POSITION, DEFAULT\_SIZE, [],  
LB\_SINGLE)  
evt\_listbox @v\_list, :on\_video\_pressed  
right\_sizer.add @v\_list

@t\_list = ListBox.new(right\_p, -1, DEFAULT\_POSITION, DEFAULT\_SIZE, [],  
LB\_SINGLE)  
evt\_listbox @t\_list, :on\_trick\_pressed  
right\_sizer.add @t\_list  
top\_sizer.add(right\_p, 1, ALIGN\_RIGHT, 2)  
@top\_p.sizer = top\_sizer  
self.sizer = global\_sizer  
show  
end

Note that the @bottom\_p isn’t used, but will be later, once I have fixed  
that.  
So the problematic code lies with the right\_sizer and the right\_p (p for  
Panel)  
The @v\_list is the upper ListBox and @t\_list is the bottom one.

Appreciate the help,

Pierre

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 14, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/listboxs-overlapping/165211/2 "2009-04-14T14:15:43Z")

</div>

Hi Pierre

Pierre P. wrote:

> Here is my code:
> 
> def initialize title, xml\_h

[…]

I’m afraid that most people who might be able to help with this don’t  
have time to work through a long snippet this copied straight from an  
application, and figure out what’s going on. If you want help with code,  
please reduce it to a bare minimum that runs on its own, and  
demonstrates just the problem. Please see the guidelines here:

[http://wxruby.rubyforge.org/wiki/wiki.pl?MailingLists](http://wxruby.rubyforge.org/wiki/wiki.pl?MailingLists)

The kind of problem you describe with items overlapping is usually  
caused by failing to add some control to a sizer, or adding it to the  
wrong sizer (eg not one belonging to its parent). I would check through  
the controls for this. Perhaps also consider using or at least  
prototyping using an XRC editor like DialogBlocks for layouts, which can  
really help understanding sizers.

Lastly I suggest also reading the Style Guide, which will help you  
structure and write wxRuby code in a more readable way:

[http://wxruby.rubyforge.org/wiki/wiki.pl?StyleGuide](http://wxruby.rubyforge.org/wiki/wiki.pl?StyleGuide)

hth  
alex

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [April 15, 2009, 2:42am UTC](https://www.ruby-forum.com/t/listboxs-overlapping/165211/3 "2009-04-15T02:42:53Z")

</div>

Alex,

Thanks again for this reply as well.  
Actually, I have fixed that issue, by simplifying the behavior (not 100%  
what I wanted) and also changing the sizer.

Thanks also for that Style Guide, it will definitely help me.

Cheers!
