How to display ListCtrl_virtual using xrcise

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
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL 500,300 wxLC_REPORT|wxLC_VIRTUAL
  • testlistctrlbase.rb (xrcise output)
    class TestFrameBase < Wx::Frame

      attr_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

On 18/04/2010 13:10, Ken Uraya wrote:

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.

I can’t test this right now, but looking over your code, a couple of
things to try:

  • don’t use on_init to do start up - just call the superclass
    constructor then carry on.

  • you may need to do set_column_width to set out the columns

a

Hi Alex,

Thank you very much for your reply.
I applied your two suggestions to my program.
However the result was the same.

Here is my modified sample code:
#!/usr/bin/ruby

require ‘rubygems’
require ‘wx’

require ‘testlistctrlbase.rb’

module TestListCtrl
def set_list_ctrl
insert_column(0, ‘first’)
insert_column(1, ‘second’)

self.set_column_width(0, 250)
self.set_column_width(1, 250)

self.item_count = 10

end

def on_get_item_text(item, col)
‘foo’
end
end

class TestFrame < TestFrameBase
def setup
@m_listctrl3.set_list_ctrl
end
end

class TestApp < Wx::App
def on_init
f = TestFrame.new
f.setup
f.show
return true
end
end

TestApp.new.main_loop

Regards,
Ken Uraya