pythonfindwxpythonlistctrl

wxPython: ListCtrl finding the item with given string


I have created a wx.ListCtrl and I have filled out the content. How do I retrieve the item with a given string?

I have used FindItem, but it always returns -1 (Not found). Am I using it incorrectly?

print self.List.FindItem(-1, "kid_inst")

>>> -1

I have: wxPython 2.8.10.1, Windows 7, Python 2.4


Solution

  • An alternative way to this situation, instead of using FindItem:

    When adding items to the ListCtrl, create a dictionary to store the location of each item.

    When given the name of the item and when we want to select that in the ListCtrl, use search the location through the dictionary, then use GetItem to get the actual item and finally Select.

    item = ListCtrl_name.GetItem(instance_location_dictionary [item_name])
    ListCtrl_name.Select(item.GetId())