AppendItem (const wxVector< wxVariant > &values, wxClientData *data=NULL)
So once a row is selected how do I get the wxClientData for the selected row so
I can reference back to the actual db record it came from? I'm not seeing a
method to do that.
Or am I barking up the wrong tree?
Thanks,
Michael
Passing client data to that method probably won't work right as it is
taking a sequence of values, and so the C++ method is probably expecting
a matching C array of data values if it is not NULL. However the
wxClientData typemap in wxPython is only going to be able to deal with
one data object there.
However you should be able to use SetItemData and GetItemData instead.
They are methods that wxPython adds on to the class, their C++
prototypes look like this:
PyObject* GetItemData(unsigned int row);
void SetItemData(unsigned int row, PyObject* data);
--
Robin Dunn
Software Craftsman
http://wxPython.org
Thanks, that should work.
But I wonder why AppendItem() doesn't return the row that was added. Seems it
would be natural to do:
for key,val in dic.items():
row = ctrl.AppendItem(val)
ctrl.SetItemData(row, key)
Otherwise it appears I'll have to maintain a counter as I loop thru my data
items and my code will look suspiciously like FORTRAN.
Is there a better way I'm missing?
Thanks,
Michael
I need to correct my earlier statement about AppendItem and friends,
apparently I didn't put my brain in gear when I glanced at the code...
void AppendItem( const wxVariantVector &values, wxClientData *data
= NULL );
While that does expect to get a sequence of items for the first
parameter, it is not for multiple rows as I mentioned before, but rather
for each of the items in a single row. Consequently the data value if
provided should be just a single object and will be associated with that
row.
>> However you should be able to use SetItemData and GetItemData instead.
>> They are
>> methods that wxPython adds on to the class, their C++ prototypes look
>> like this:
>>
>> PyObject* GetItemData(unsigned int row);
>> void SetItemData(unsigned int row, PyObject* data);
>
And you can still use GetItemData to fetch it later, or SetItemData to
change the data value.
> Thanks, that should work.
>
> But I wonder why AppendItem() doesn't return the row that was added.
> Seems it would be natural to do:
>
> for key,val in dic.items():
> row = ctrl.AppendItem(val)
> ctrl.SetItemData(row, key)
>
> Otherwise it appears I'll have to maintain a counter as I loop thru my
> data items and my code will look suspiciously like FORTRAN.
>
> Is there a better way I'm missing?
Well, you know that if you've just appended an item then its row number
will be one less than the number of items in the data store, so
something like this would work:
row = self.GetStore().GetCount()
> And you can still use GetItemData to fetch it later, or SetItemData to change
> the data value.
This seems to be working very well and is plenty pythonic.
Thanks,
Michael