Hi,
I’m trying to display text in a ListCtrl_virtual using xrcise.
To display text, I implemented on_get_item_text() method in TestListCtrl
module.
However, no text displayed in my list.
I’d appreciate it if you could teach me how to display text.
My environment:
ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i386-mswin32]
gem list
*** LOCAL GEMS ***
wx_sugar (0.1.22)
wxruby (2.0.1)
Here is my sample code:
- testlistctrl.xrc
-
testlistctrlbase.rb (xrcise output)
class TestFrameBase < Wx::Frameattr_reader :m_listctrl3 def initialize(parent = nil) super() xml = Wx::XmlResource.get xml.flags = 2 # Wx::XRC_NO_SUBCLASSING xml.init_all_handlers xml.load("testlistctrl.xrc") xml.load_frame_subclass(self, parent, "TestFrame") finder = lambda do | x | int_id = Wx::xrcid(x) begin Wx::Window.find_window_by_id(int_id,
self) || int_id
# Temporary hack to work around regression in
1.9.2; remove
# begin/rescue clause in later versions
rescue RuntimeError
int_id
end
end
@m_listctrl3 = finder.call("m_listCtrl3")
@m_listctrl3.extend(TestListCtrl)
if self.class.method_defined? "on_init"
self.on_init()
end
end
end
- testlistctrl.rb (main)
#!/usr/bin/ruby
require ‘rubygems’
require ‘wx’
require ‘testlistctrlbase.rb’
module TestListCtrl
def on_init
insert_column(0, ‘first’)
insert_column(1, ‘second’)
self.item_count = 10
end
def on_get_item_text(item, col)
‘foo’
end
end
class TestFrame < TestFrameBase
def initialize
super
end
def on_init
@m_listctrl3.on_init
@m_listctrl3.refresh_items(0, 9)
end
end
class TestApp < Wx::App
def on_init
f = TestFrame.new.show
return true
end
end
TestApp.new.main_loop
Regards,
Ken Uraya