Note - this can be written ListCtrl.new(self, :style => LC_REPORT). You
almost never need to use the clumsy ‘DEFAULT_POSITION’, ‘DEFAULT_SIZE’
etc. Use named arguments and these will be taken care of.
li = ListItem.new()
li.set_state
li.set_text '123'
@list.insert_item(li)
li.set_text '234'
@list.insert_item(li)
Your problem is here, I think. Each ListItem object represents a unique
object in the list. The row it’s in is identified by an attribute ‘id’.
However, you’re adding the same object multiple times. Do it like this
instead, creating a new ListItem for each:
li = Wx::ListItem.new
li.state = LIST_STATE_SELECTED
li.id = 0 # For row 0
li.text = ‘123’ @list.insert_item li
Note - this can be written ListCtrl.new(self, :style => LC_REPORT). You
almost never need to use the clumsy ‘DEFAULT_POSITION’, ‘DEFAULT_SIZE’
etc. Use named arguments and these will be taken care of.
This is great! I’ve always been annoyed by that, since I practically
never need to explicitly set those using sizer based layout.
li = ListItem.new()
li.set_state
li.set_text '123'
@list.insert_item(li)
li.set_text '234'
@list.insert_item(li)
I didn’t use the ListItem helper-class in the original program. Just
wanted to make it easier for you to reproduce the problem by selecting
the items at startup. I was using @list.insert_item(pos, ‘item’) and @list.set_item(pos, col, ‘property’) originally.
Your problem is here, I think. Each ListItem object represents a unique
object in the list. The row it’s in is identified by an attribute ‘id’.
However, you’re adding the same object multiple times. Do it like this
instead, creating a new ListItem for each:
li = Wx::ListItem.new
li.state = LIST_STATE_SELECTED
li.id = 0 # For row 0
li.text = ‘123’ @list.insert_item li
I’ve been playing around with this now. I thought, it might also be a
problem of references getting lost somewhere. So I modified it as
follows: