# Problem with ListCtrl Width

**URL:** <https://www.ruby-forum.com/t/problem-with-listctrl-width/163661>\
**Category:** wxRuby\
**Created:** [March 23, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/problem-with-listctrl-width/163661 "2009-03-23T18:45:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [March 23, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/problem-with-listctrl-width/163661/1 "2009-03-23T18:45:42Z")

</div>

I’m still learning wxWidgets, so this is probably basic.

I have some data that I’m trying to display in a wxListCtrl. The  
ListCtrl is in a Box Sizer that is stacked in a main box sizer. the list  
control is the only control in the specific box sizer containing it.

The problem is that the sizer is squeezing the width of the list control  
down to the point that only a column and a half are visible without  
horizontal scrolling. The form is actually wide enough that it should be  
able to display all the columns.

How do I tell the layout to expand the width of the wxListCtrl?

Here’s my code for the ListCtrl:

#Put the item list on the screen  
@itemSizer = Wx::BoxSizer.new(Wx::HORIZONTAL)  
@itemList = Wx::ListCtrl.new(self, -1,  
Wx::DEFAULT\_POSITION, Wx::DEFAULT\_SIZE,  
Wx::LC\_REPORT | Wx::LC\_HRULES | Wx::LC\_VRULES)  
row = 0  
@itemList.insert\_column(0, “Date”)  
@itemList.insert\_column(1, “Start”)  
@itemList.insert\_column(2, “End”)  
@itemList.insert\_column(3, “Description”)  
@itemList.insert\_column(4, “Elapsed”)  
@itemList.insert\_column(5, “No Charge”)  
@itemSizer.add(@itemList, 1, Wx::TOP | Wx::LEFT, 15)  
@mainSizer.add(@itemSizer, 1, Wx::ALIGN\_LEFT | Wx::LEFT |Wx::BOTTOM,  
15)

Thanks in advance  
—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [March 23, 2009, 9:19pm UTC](https://www.ruby-forum.com/t/problem-with-listctrl-width/163661/2 "2009-03-23T21:19:14Z")

</div>

Hi Michael,

my advice would be:

1. go to this page: [http://wxruby.rubyforge.org/doc/sizer.html#Sizer\_add](http://wxruby.rubyforge.org/doc/sizer.html#Sizer_add)  
and read it once or twice
2. go and fetch an evaluation copy of DialogBlocks here:  
[Download DialogBlocks](http://www.anthemion.co.uk/dialogblocks/download.htm)

DialogBlocks flattens your learning curve a lot if you’re more of the  
learning by doing type of guy…

And pay special attention to the Wx::EXPAND flag and the proportion  
parameter 😉

Christian.

Michael S. wrote:

> I’m still learning wxWidgets, so this is probably basic.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [March 23, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/problem-with-listctrl-width/163661/3 "2009-03-23T21:51:23Z")

</div>

Michael S. wrote:

> The problem is that the sizer is squeezing the width of the list control  
> down to the point that only a column and a half are visible without  
> horizontal scrolling. The form is actually wide enough that it should be  
> able to display all the columns.
> 
> How do I tell the layout to expand the width of the wxListCtrl?

Hard to be certain without seeing the whole context, but I’d guess you  
should be adding a Wx::GROW flag to the sizer#add calls. This tells the  
Sizer to expand that item to fill all the space in the non-main sizer  
direction. So, if the sizer’s vertical, adding Wx::GROW (or Wx::EXPAND,  
it’s a synonym), the listctrl will fill all the horizontal space  
available.

A few random hints:

> Here’s my code for the ListCtrl:
> 
> #Put the item list on the screen  
> @itemSizer = Wx::BoxSizer.new(Wx::HORIZONTAL)

@itemSizer = Wx::HBoxSizer.new

And, are you sure you need two sizers?

> @itemList = Wx::ListCtrl.new(self, -1,  
> Wx::DEFAULT\_POSITION, Wx::DEFAULT\_SIZE,  
> Wx::LC\_REPORT | Wx::LC\_HRULES | Wx::LC\_VRULES)

@itemList = Wx::ListCtrl.new(self, :style =\>  
Wx::LC\_REPORT|Wx::LC\_HRULES|Wx::LC\_VRULES)

alex
