From: "Maximilian Bräutigam" Date: 2009-09-05T20:07:19+09:00 Subject: Filling Wx::ListCtrl with contents --=-5rpRYsyohDlVaiJuYaWC Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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 -- Maximilian Br��utigam max-braeu@gmx.de http://www.jcf.uni-jena.de/ --=-5rpRYsyohDlVaiJuYaWC Content-Disposition: attachment; filename="testframe.rb" Content-Type: application/x-ruby; name="testframe.rb" Content-Transfer-Encoding: 7bit #!/usr/bin/env ruby # -*- coding: utf-8 -*- begin require 'rubygems' rescue LoadError end begin require 'wx' rescue LoadError puts "Error loading library/module: wx not found" exit 1 end class MyFrame < Wx::Frame def initialize(title) super( nil, :title => title, :size => [ 800 , 600 ], :style => Wx::DEFAULT_FRAME_STYLE ) menu_bar = Wx::MenuBar.new menu_file = Wx::Menu.new menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program") menu_bar.append(menu_file, "&File") self.menu_bar = menu_bar @listctrl = Wx::ListCtrl.new( self , :style => Wx::LC_REPORT|Wx::LC_VIRTUAL|Wx::LC_HRULES|Wx::LC_VRULES ) @listctrl.insert_column(0, "key") @listctrl.insert_column(1, "description") @listctrl.insert_column(2, "creation time") @listctrl.insert_column(3, "last update") @listctrl.set_column_width(0, 80) @listctrl.set_column_width(1, 420) @listctrl.set_column_width(2, 150) @listctrl.set_column_width(3, 150) @listctrl.set_item_count(2) def @listctrl.on_get_item_text(item, col) # i want to do the following: # contentarray = get_contents() # contentarray = frame.get_contents() # contentarray = MyFrame::get_contents() # all of these methods are not working of course, but i see no way!? contentarray = [ [ "Ruby" , "Ruby Test Description" , "2009-12-15 12:34", "2010-04-05 11:24" ] , [ "C++" , "C++ Test Description" , "2008-10-02 15:54", "2009-05-05 14:45" ] ] return "#{contentarray.at(item).at(col)}" end create_status_bar(1) self.status_text = "I need help, plz! Select an Item ..." @listctrl.evt_list_item_selected(@listctrl.get_id()) {|event| on_item_selected(event)} evt_menu Wx::ID_EXIT, :on_quit end def on_quit close() end def on_item_selected(event) item = event.get_item() # is it possible to access the data this way? # of course i can get the data via index if my contentarray is accessible. self.status_text = "Index: #{event.get_index()}. Contents: #{item.get_data()}." end def get_contents() # returns the data contentarray = [ [ "Ruby" , "Ruby Test Description" , "2009-12-15 12:34", "2010-04-05 11:24" ] , [ "C++" , "C++ Test Description" , "2008-10-02 15:54", "2009-05-05 14:45" ] ] end end Wx::App.run do self.app_name = 'testframe' frame = MyFrame.new("testframe") frame.set_min_size( [ 600 , 400 ] ) frame.centre frame.show end --=-5rpRYsyohDlVaiJuYaWC--