Forum: wxRuby listcontrol problem

Posted by Bruce Loving (Guest)
on 2010-07-25 13:58
(Received via mailing list)
trying to create a list control, filling with data, but it wont scroll
vertically or respond to mouse click.
-------------------------------------------
require 'rubygems'
require 'wx'
include Wx

class MyFrame < Wx::Frame
    def initialize()
        super(nil,-1,'Wristband Manager',:size => [300,400])
        @my_panel = Panel.new(self)
        show()
    end
end

class MasterList < Wx::ListCtrl
  def initialize(parent)
     super(parent,:size => [250,200],:style => Wx::LC_REPORT)
     create_layout
     add_entries
   end

  def create_layout
     self.insert_column(0, "Name")
     self.insert_column(1, "Courses")
     self.insert_column(2, "Band")
     self.set_column_width(0,100)
     self.set_column_width(1,25)
     self.set_column_width(2,50)
  end

def add_entries
    name = 'Test01'
    50.times do |idx|
       item0 = Wx::ListItem.new
       item0.set_text(name)
       item0.set_column(0)
       item0.set_id(idx)
       self.insert_item(item0)

       item1 = Wx::ListItem.new
       item1.set_text("15")
       item1.set_column(1)
       item1.set_id(idx)
       self.set_item(item1)

    item1 = Wx::ListItem.new
       item1.set_text("Green")
       item1.set_column(2)
       item1.set_id(idx)
       self.set_item(item1)
    name.succ!
    end
   end


end

class MyApp < App
    def on_init
        frame1 = MyFrame.new
    MasterList.new frame1
    end
end

MyApp.new.main_loop()
Posted by Hameed Gifford (hamstap85)
on 2010-07-25 18:44
(Received via mailing list)
Okay, I'm noticing a few things here:

1.
include Wx # if you have this, you don't have to have Wx:: in front of
Wx classes or modules

2.
# in MasterList#add_entries
item1 = Wx::ListItem.new
item1.set_text("Green")
# ...
name.succ!
end
# you might want to find a different local name for this ListItem, since
it might be interfering with the one above it, unless that's what you
intend.

3.
# in My_App#on_init
MasterList.new frame1 # you might want to create the master list within
frame1, and set parent to self


If those don't do anything, let someone else tell you what to do.

- Hameed
Posted by Bruce Loving (Guest)
on 2010-07-25 18:57
(Received via mailing list)
Thanks, #3 did the trick!
Posted by Hameed Gifford (hamstap85)
on 2010-07-26 07:28
(Received via mailing list)
No prob. Generally, you want to create window object within the
initialize of the parent object. Keeps problems from happening.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.