[wxPython-users] Virtual ListCtrl and GetItemData: recursion error
Wojciech Śmigaj
w.smigaj at gmail.com
Sun Jul 22 02:25:31 PDT 2007
Stephen Hansen wrote:
> It looks as if each call of GetItemData() resulted in a new call of the
> OnGetItemText() function -- I don't understand why (could it be a
> bug in wxWidgets/wxPython?).
>
[...]
>
> You can't use GetItemData (or really even SetItemData) because those are
> meant for accessing the internal store of the normal control.
>
> You have to do something like:
>
> class VirtualList(wx.ListCtrl):
> def __init__(self, parent, id=-1):
> wx.ListCtrl.__init__(self, parent, id,
> style=wx.LC_REPORT | wx.LC_VIRTUAL)
>
> # Initialize items
> ids = [0, 1, 2]
> self.SetItemCount(len(ids))
>
> self._data = {}
>
> for n, id in enumerate(ids):
> self._data[n] = id
>
> # Create headers
> self.InsertColumn(0, "Col 0")
> self.InsertColumn(1, "Col 1")
>
> def OnGetItemText(self, item, col):
> return self._GetRowFromDatabase(self._data[item])
>
> def _GetRowFromDatabase(self, id):
> return 'foo'
>
> Etc.
Hi Stephen,
thanks for the answer. I'll follow your suggestion. Initially I thought
that, despite not holding the text/images etc. for particular items, a
virtual list should at least offer the possibility to associate the
integer "data" to be used as the key (which would then stay unchanged if
the list was resorted etc.).
Best regards,
Wojciech Smigaj
More information about the wxpython-users
mailing list