[wxPython] problem with wxListCtrl - itemDataMap vs. DeleteItem

I would suggest two places to look:

1. DeleteItem needs an ordinal, while itemDataMap is referenced by key. If
the two don't match, you are out of sync. Remember that the ordinals all
change when you do the sort. You might post your "delete" code so we can
take a look.

2. Adding/updating represents a great place to get out of sync. You might
post the add/update code as well, just so another set of eyes can look it
over.

If I were debugging this, I'd dump the itemDataMap keys to a log somewhere
after each delete and each add/update, and compare that to the actual
contents of the list control.

···

On Thu, 5 Sep 2002 22:38:45 -0700, Stephen Bartlett <stephen@bartlettsoftware.biz> wrote:

My app receives a posted wxEvent at some point, and in the corresponding
method the app may add/update items. In lockstep with using
listCtrl.InsertStringItem and listCtrl.SetStringItem, the app also
adds/updates values in the itemDataMap structure. At the very end of this
code, I use this to re-sort the listCtrl:
   self.list.SortItems(self.GetColumnSorter())
So far so good.

Later, in response to a right-click popup menu item, I want to delete the
selected item(s). I use DeleteItem, of course. I also "del
self.itemDataMap[key]" so as to keep the listCtrl and the itemDataMap in
sync. Again, no problem.

But on the very next occurrance of the wxEvent mentioned above (in which
I may add/update items), at the tail end I hit that line of code that
re-sorts the list, and it raises "Mapping key not found" in
../wxPython/lib/mixins/listctrl.py line 106

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

1. DeleteItem needs an ordinal, while itemDataMap is referenced by key. If
the two don't match, you are out of sync. Remember that the ordinals all
change when you do the sort. You might post your "delete" code so we can
take a look.

Thanks, that was the clue I needed. I'd gotten off-track about the item
ordinal (aka itemID) vs. itemDataMap key concept. I was also trying to be
clever and respond to OnItemDelete to clean up the itemDataMap, but that's
too late -- by the time you get notified in that method the item is already
gone, and using GetItemData at that point hands you the key for a different
item than you're expecting.

If I were debugging this, I'd dump the itemDataMap keys to a log somewhere
after each delete and each add/update, and compare that to the actual
contents of the list control.

Did so, and that proved useful too.

Thanks Again,
- Stephen

···

On Friday 06 September 2002 10:03 am, Tim Roberts wrote:

--
Stephen Bartlett, President
Bartlett Software, Inc.
http://www.bartlettsoftware.biz/