Filling Wx::ListCtrl with contents

Hi all,

I’ve got a question concerning ListCtrl_virtual of wxRuby since I see no
way filling the list with dynamic contents. I’m new to Ruby so I maybe
have to apologise for my request.

The problem is, that I have to define the on_get_item_text(item, col)
function. There I would like to use the item and col variables to read
data from a two-dimensional array. My very problem is, that I do not
know how to transfer the array from another function to
on_get_item_text(item, col) or better on_get_item_text(item, col,
array). I attached a rubyscript showing what I mean.

I would be very grateful, if you could give me a solution of this
problem ― maybe modify my testscript.

And/Or please show me how to use the approach via ListItems because the
samplefile
http://wxruby.rubyforge.org/doc/samplelistctrl.html
at the website
http://wxruby.rubyforge.org/doc/listctrl.html
is not accessible. I tinkered with it but it doesn’t really work.

Thank you very much in advance for your kind help.
Kind regards,
der Max

Hi

Maximilian Bräutigam wrote:

The problem is, that I have to define the on_get_item_text(item, col)
function. There I would like to use the item and col variables to read
data from a two-dimensional array. My very problem is, that I do not
know how to transfer the array from another function to
on_get_item_text(item, col) or better on_get_item_text(item, col,
array). I attached a rubyscript showing what I mean.

I’m not 100% sure this is what you want, but if you want the ListCtrl to
access the data from the frame, you could just write (in your
on_get_item_text method)

parent.get_contents.at(item).at(col)

“parent” is a method available on all Windows which returns the
containing frame/panel/etc.

Or you could also split out your listctrl into a separate subclass.

Also, there is much simpler syntax than you’re using for event handlers,
where you have

@listctrl.evt_list_item_selected(@listctrl.get_id()) {|event|

on_item_selected(event)}

you could just writen

evt_list_item_selected(@listctrl, :on_item_selected)

hth
alex

Alex F. wrote:

Hi Alex,

Is there any sample code for a Wx::ListCtrl? On this page:

http://wxruby.rubyforge.org/doc/listctrl.html

the link to the sample code located here:

http://wxruby.rubyforge.org/doc/samplelistctrl.html

produces a 404 Not Found error.

On my own, I could not figure out how to add items to the different
columns of a “report view” styled Wx::ListCtrl,

require ‘rubygems’
require ‘wx’

class MyFrame < Wx::Frame

def initialize
super(nil,
:title => “Test”,
:size => [600, 400])

panel = Wx::Panel.new(self)

my_list = Wx::ListCtrl.new(panel,
                       :name => "Drinks",
                       :size => [400, 100],
                       :style => Wx::LC_REPORT)

my_list.insert_column(0, "Drinks")
my_list.insert_column(1, "Extras")

=begin
my_list.set_item(0, 0, “coffee”)
my_list.set_item(1, 0, “tea”)
my_list.set_item(2, 0, “water”)
=end

my_list.insert_item(0, "coffee")
my_list.insert_item(1, "tea")
my_list.insert_item(2, "water")

show

end

end

class MyApp < Wx::App
def on_init
MyFrame.new
end
end

MyApp.new.main_loop

How would I add items to the second column?

Am Samstag, den 05.09.2009, 20:22 +0200 schrieb 7stud --:

                       :name => "Drinks",

=end
class MyApp < Wx::App
def on_init
MyFrame.new
end
end

MyApp.new.main_loop

How would I add items to the second column?

Hi 7stud,

with the help of Alex I was able to modify my testscript so it’s
working. Honestly, I’m not using ListItems but ListCtrl_virtual.

Try it out.
Kind regards,
der Max

hi

7stud – wrote:

On my own, I could not figure out how to add items to the different
columns of a “report view” styled Wx::ListCtrl,

How would I add items to the second column?

Call insert_item first to create the row, then use set_item to set the
text in the secondary columns. In your sample, something like:

my_list.insert_item(0, "coffee")
my_list.set_item(0, 1, "milk")
my_list.insert_item(1, "tea")
my_list.set_item(1, 1, "sugar")
my_list.insert_item(2, "water")
my_list.set_item(2, 1, "bubbles")

alex

Alex F. wrote:

Call insert_item first to create the row, then use set_item to set the
text in the secondary columns. In your sample, something like:

my_list.insert_item(0, "coffee")
my_list.set_item(0, 1, "milk")
my_list.insert_item(1, "tea")
my_list.set_item(1, 1, "sugar")
my_list.insert_item(2, "water")
my_list.set_item(2, 1, "bubbles")

alex

Thanks Alex. Can you fix that broken link as well?