[wxruby-users] Working with ListCtrl and ListItem

Alex Fenton
Sat, 24 Oct 2009 11:01:37 -0000

hi timo

Timo Springmann wrote:

...

> I think it would be better to subclass Wx::ListItem and add instances
> of this class to the List. Something like this (not tested):
>
> class MyListItem < Wx::ListItem
>   def initialize(data_object, *args)
>     super(*args)
>     # here I need to add the column data, but I don''t know how
>   end
> end
>
> my_list.add_item(MyListItem.new(data_object))
>
> But I have no idea how I can fill the columns in my ListItem-Object.
> Any ideas how I can do this? I think it should work with
> ListItem#set_data and/or ListItem#set_column but I don''t
understand
> the docs.

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:

http://rubyforge.org/pipermail/wxruby-users/2009-September/004955.html

If you have an underlying data model eg linked to a RDBMS, it can be a
lot tidier to use Wx::LISTCTRL_VIRTUAL, and supply a set of methods to
populate the listctrl automatically. Take a look at the samples dir
(there''s an example in sapmles/bigdemo I think).

cheers
alex