tullaman
tullaman

Reputation: 176

wx.ListCtrl: telling a user's Click from program's a_listctrl.Select()

A first question post to SO.

When a user clicks on a ListCtrl widget it generates a EVT_LIST_ITEM_SELECTED event. However if I want set up the list before display to the user so that several items are already highlighted (by calling Select() on the ListCtrl) the widget generates the same event. This event is the incorrectly processed by my application as if it were a real user selection.

As wxPython uses message passing I cannot simply set a flag (ignore_selection_events) before I do my programatic selections and then clear it afterward. As in all likelyhood the flag will have been cleared before the first EVT_LIST_ITEM_SELECTED handler/call-back is invoked.

Some solutions I tried and what went wrong:

Okay over to you SO!

UPDATE:

Thanks Jeff! Some more info based on what I tried.

list_ctrl.SetItemState(item_index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) #works
list_ctrl.SetItemState(item_index, 0xFFFFFFFF, wx.LIST_STATE_SELECTED) #works
list_ctrl.SetItemState(item_index, 1, wx.LIST_STATE_SELECTED) # does NOT work

So the use of both the state and mask args is so that you can easily modify the item state without having to first read the current state, OR in the required modification bits and then write back.

Upvotes: 3

Views: 1389

Answers (1)

minou
minou

Reputation: 16553

Try SetItemState. I use the following in my code to deselect an item:

self.ballotC.SetItemState(c, 0, wx.LIST_STATE_SELECTED) 

I would try

self.ballotC.SetItemState(c, 1, wx.LIST_STATE_SELECTED)

or

self.ballotC.SetItemState(c, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) 

to select an item. There is some documentation here. It isn't as clear as it could be so you have to play around a bit until you get it right.

Upvotes: 1

Related Questions