get item text of wx.listctrl

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

get item text of wx.listctrl

Nathan Smith
Hi all

I have a wx.listctrl, which is bound to fire self.update() when ever the
focused item changes.

My question is, I have three lists:

self.year,

self.month

and self.day

I can get the focussed item number: self.year.GetFocusedItem()

but How do I get that items text, so instead of it telling me that item
0 is focused, it tells me that 2018 is focused.

Thanks a lot

Nate

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: get item text of wx.listctrl

GadgetSteve


On 16/09/2018 11:34, Nathan smith wrote:

> Hi all
>
> I have a wx.listctrl, which is bound to fire self.update() when ever the
> focused item changes.
>
> My question is, I have three lists:
>
> self.year,
>
> self.month
>
> and self.day
>
> I can get the focussed item number: self.year.GetFocusedItem()
>
> but How do I get that items text, so instead of it telling me that item
> 0 is focused, it tells me that 2018 is focused.
>
> Thanks a lot
>
> Nate
>

Nate,

It looks like the documentation may need some clarification on the
distinction between an Item and an Item Index or ID - unless I am
misreading:

item_index = self.year.GetFocusedItem()
if item_index != -1:
     txt = self.year.GetItem(item_index).GetItemText()

Should do the job.

The demo code uses:

     def OnItemSelected(self, event):
         ##print(event.GetItem().GetTextColour())
         self.currentItem = event.Index
         self.log.WriteText("OnItemSelected: %s, %s, %s, %s\n" %
                            (self.currentItem,
                             self.list.GetItemText(self.currentItem),
                             self.getColumnText(self.currentItem, 1),
                             self.getColumnText(self.currentItem, 2)))

in the wx.EVT_LIST_ITEM_SELECTED handler. Changing the 3rd line to:
         self.currentItem = self.list.GetFocusedItem() #event.Index
still works nicely. :-)

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
https://www.avg.com

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.