wx.ListCtrl how select a specific item after reload data?

890 views
Skip to first unread message

Beppe

unread,
Nov 22, 2010, 11:38:09 AM11/22/10
to wxPython-users
Hi,

how can I select a specific item from a wx.ListCtrl (style =
wx.LC_REPORT)?

I use to save the item selected in a wx.ListCtrl with...

my.index = self.lstEquipments.GetFirstSelected()

and when I need to refresh all data on listbox, I would to re-select
previous item using

frame_instance.listbox_name.Select(my.index,True)

or

frame_instance.listbox_name.SetItemState(my.index, 1,
wx.LIST_STATE_SELECTED)

but nothing work.
Any suggestions.

regards
Beppe




Steve Barnes

unread,
Nov 22, 2010, 11:54:04 AM11/22/10
to wxpytho...@googlegroups.com

Hi,

my.index = self.lstEquipments.GetFirstSelected()

frame_instance.listbox_name.Select(my.index,True)

or

frame_instance.listbox_name.SetItemState(my.index, 1,
wx.LIST_STATE_SELECTED)

regards
Beppe

Beppe,

Try:
item = frame_instance.listbox_name.GetItem(my.index)
item.SetItemState(wx.LIST_STATE_SELECTED)

You may also need a:
frame_instance.listbox_name.SetItem(item)

Gadget/Steve

Beppe

unread,
Nov 23, 2010, 1:44:10 AM11/23/10
to wxPython-users
Hi Steve,
thanks for your tip,
I have clear up,at moment on Debian Lenny, with

#retrive index from a listbox, lstEquipments is a wx.ListCtrl
my.index = self.lstEquipments.GetFirstSelected()
#in another module
def on_my_event():
frame_instance.lstEquipments.SetItemState(my.index , 0,
wx.LIST_STATE_SELECTED)
frame_instance.lstEquipments.SetItemState(my.index,wx.LIST_STATE_SELECTED,wx.LIST_STATE_SELECTED)
frame_instance.lstEquipments.Select(my.index,1)

in practice it seems that I need first to de-select the row and after
select it.

regards
Beppe
Reply all
Reply to author
Forward
0 new messages