I made a list which I named “list_ctrl” and I am wondering how I retrieve the information I have selected in it. For example, let’s say I have a list of cars. In the list there might me “Volvo, BMW, Mercedes” etc. If I select BMW, how do I get that information into a variable when I press a button?
Bind to wx.EVT_LIST_ITEM_SELECTED and then in the handler, grab the item index with:
currentItem = event.m_itemIndex
Then you can use the various Getters to get the rest of the information you need, such as GetItem. Personally, I prefer setting up a dictionary (see wxPython: wx.ListCtrl Tips and Tricks - Mouse Vs Python) or just using ObjectListView instead of ListCtrl (wxPython: Using ObjectListView instead of a ListCtrl - Mouse Vs Python). See also the docs: wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
Also, is there a way to make it so I can only select one item from the list and not multiple by using shift?
Use the wx.LC_SINGLE_SEL style flag when you create it
- Mike
···
On Monday, July 23, 2012 2:27:17 AM UTC-5, Jonathan Persson wrote: