Listcontrol problem

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()

Okay, I’m noticing a few things here:

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

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.

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

Thanks, #3 did the trick!

No prob. Generally, you want to create window object within the
initialize of the parent object. Keeps problems from happening.