[wxruby-users] Working with ListCtrl and ListItem

Timo Springmann
Mon, 26 Oct 2009 23:42:53 -0000

Hi Alex,

Am 24.10.2009 um 13:01 schrieb Alex Fenton:
>
> Yes, the wxWidgets API for working with multiple columns is not so
> obvious. You do need to have one ListItem for every single cell -
> you can''t combine several columns of a single row into one. Have a
> look at this thread:

Because of the un-sortable VIRTUAL list style  I took a deeper look
into the normal ListCtrl. You wrote, that I need one ListItem for
every single cell. After reading the docs I thought I understand how
it works, but I still can''t get it to do what I want.

I _thought_ the following code would create a ListCrtl with two
columns populated with one line filling both columns with some text.
But both items (item0 and item1) will put it''s text into the first
cell (column 0). It seems like "self.set_column(0)" doesn''t
do
anything... any ideas?

class MyList < Wx::ListCtrl

   def initialize()
     super(:style => Wx::LC_REPORT|Wx::LC_HRULES)
     self.insert_column(0, "Col1")
     self.insert_column(1, "Col2")
     self.set_column_width(0,280)
     self.set_column_width(1,300)
     add_entries
   end

   def add_entries
       item0 = Wx::ListItem.new
       item0.set_text("Some text for column 0")
       item0.set_column(0)
       item0.set_id(0)
       self.insert_item(item0)

       item1 = Wx::ListItem.new
       item1.set_text("Some other text for column 1")
       item1.set_column(1)
       item1.set_id(0)
       self.insert_item(item1)
   end
end

Regards,
Timo

P.S.: I know I could use self.insert_item and self.set_item in this
case (and it would work), but later I would like to move the creatin
of the list items to an own class.