I have a ListCtrl with all the items having the client data. How can I retreive an item index if I have only the client data?
Simone
Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
I have a ListCtrl with all the items having the client data. How can I retreive an item index if I have only the client data?
Simone
Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
It is actually pretty common the way it is described by Simone.
Consider a mechanism where an object gets selected by the framework
and you as view have to respond by highlighting that one in the
wxListBox. Then you search for the object pointer in the client data
and select the item. The framework does not know about indexes of your
wxListCtrl only about the object that it needs to manage
- Jorgen
On Dec 19, 2007 12:34 PM, jonhattan <jonhattan@faita.net> wrote:
Simone escribió:
> I have a ListCtrl with all the items having the client data. How can I
> retreive an item index if I have only the client data?I think it only can be done by looping through the list items.
# cd is the client data you know
index = -1
for i in range(list.ItemCount):
if list.GetItemData(i) == cd:
index = i
break
if index == -1: print "not found"(untested code)
It's supposed to be used the other way: you have an item index and want
the client data: list.GetItemData(row). Just curious about the way you
obtained a client data instead of an index.
If your processing does really need to obtain indexes from client
data,... perhaps it's better to have a dict with client data as keys and
indexes as values, instead of going through a loop each time.-- jonhattan
>
> Simone
> Chiacchiera con i tuoi amici in tempo reale!
> Yahoo fa parte della famiglia di brand Yahoo.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
jonhattan ha scritto:
It's supposed to be used the other way: you have an item index and want the client data: list.GetItemData(row). Just curious about the way you obtained a client data instead of an index.
Just because the list is the result of a query on a database and the client data is the rowid of each line of the query. When I delete one record, I update the panel that shows and modifies the record, but I'm not able to select the correct item in the listctrl.
If your processing does really need to obtain indexes from client data,... perhaps it's better to have a dict with client data as keys and indexes as values, instead of going through a loop each time.
I think that's a good idea, thank you. But another question: what does ListCtrl.FindItemData return?
Simone
Chiacchiera con i tuoi amici in tempo reale! Yahoo fa parte della famiglia di brand Yahoo.