How to get row number in UltimateListCtrl?

Hi,

I have created a UltimateListCtrl, created 5 rows, and put a button on each row.
When I press one of these buttons, I want to get the row number which the button is in. How can I do this? I have looked at documentation and googled it, but couldn’t find a way.

One possible solution is that, since this is wx and
python objects are mutable you can just add a row, (or any other
thing), attribute, (as simple as the_button.RowNum = 3) to the
buttons as you add them and your event handler can use
“GetEventObject” to get the original button and recover the
attribute.
Gadget/Steve

···

On 08/08/14 02:12, steve wrote:

Hi,

    I have created a UltimateListCtrl, created 5 rows, and put a

button on each row.

    When I press one of these buttons, I want to get the row number

which the button is in. How can I do this? I have looked at
documentation and googled it, but couldn’t find a way.

  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 wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Python

Hello Gadget Steve,

I couldn’t find a direct way to do it, but I found a work around:

I enabled ULC_STICKY_HIGHLIGHT flag when creating the Ulitimate List control, this makes the row automatically highlighted (selected) when I hover on the button with mouse,
then I bind the following to the list control:

self.Bind(ULC.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.my_list_control)

def OnItemSelected(self, event):
self.currentItem = event.m_itemIndex

Here, self.currentItem gives me the row number.

Best regards

···

On Saturday, August 9, 2014 1:54:37 PM UTC+3, Gadget Steve wrote:

On 08/08/14 02:12, steve wrote:

Hi,

    I have created a UltimateListCtrl, created 5 rows, and put a

button on each row.

    When I press one of these buttons, I want to get the row number

which the button is in. How can I do this? I have looked at
documentation and googled it, but couldn’t find a way.

  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 wxpython-user...@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

One possible solution is that, since this is wxPython and
python objects are mutable you can just add a row, (or any other
thing), attribute, (as simple as the_button.RowNum = 3) to the
buttons as you add them and your event handler can use
“GetEventObject” to get the original button and recover the
attribute.

Gadget/Steve

This should always be available, even if you do not use
ULC_STICKY_HIGHLIGHT.
You might want to use event.GetIndex() instead as the “m_”
properties are deprecated and won’t be there in Phoenix.
Werner

···

Hi,

  On 8/10/2014 10:46, steve wrote:

Hello Gadget Steve,

    I couldn't find a direct way to do it, but I found a work

around:

    I enabled         ULC_STICKY_HIGHLIGHT
    flag when creating the Ulitimate List control, this makes

the row automatically highlighted (selected) when I hover on the
button with mouse,

    then I bind the following to the list control:



              self.Bind(ULC.EVT_LIST_ITEM_SELECTED,

self.OnItemSelected, self.my_list_control)

      def OnItemSelected(self, event):

          self.currentItem = event.m_itemIndex

http://docs.wxwidgets.org/trunk/classwx_list_event.html#a82f01598e75a679d3ab4bba3478b540d
http://wxpython.org/Phoenix/docs/html/classic_vs_phoenix.html?highlight=m_itemindex

Hi,

But by default, a row won’t get selected when hovered over it with mouse, if I don’t set that flag.

···

On Sunday, August 10, 2014 1:31:55 PM UTC+3, werner wrote:

Hi,

  On 8/10/2014 10:46, steve wrote:

Hello Gadget Steve,

    I couldn't find a direct way to do it, but I found a work

around:

    I enabled         ULC_STICKY_HIGHLIGHT
    flag when creating the Ulitimate List control, this makes

the row automatically highlighted (selected) when I hover on the
button with mouse,

    then I bind the following to the list control:



    self.Bind(ULC.EVT_LIST_ITEM_          SELECTED,

self.OnItemSelected, self.my_list_control)

      def OnItemSelected(self, event):

          self.currentItem = event.m_itemIndex
This should always be available, even if you do not use

ULC_STICKY_HIGHLIGHT.

You might want to use event.GetIndex() instead as the "m_"

properties are deprecated and won’t be there in Phoenix.

http://docs.wxwidgets.org/trunk/classwx_list_event.html#a82f01598e75a679d3ab4bba3478b540d

http://wxpython.org/Phoenix/docs/html/classic_vs_phoenix.html?highlight=m_itemindex

Werner

Hi Steve,

···

On 8/10/2014 12:54, steve wrote:

Hi,

But by default, a row won't get selected when hovered over it with mouse, if I don't set that flag.

Oops, didn't catch on that you wanted this on hover.

Werner

It sounded like you wanted the row on button click, not row hover.

Yes, I want the row number when I click the button.
But I couldn’t find a way to do it.
Therefore, I found that work around: I set that flag, when I hover on the button, the function I wrote above gives me the row number.

But I would appreciate if someone finds a direct solution for this issue.

···

On Sunday, August 10, 2014 8:42:51 PM UTC+3, Nathan McCorkle wrote:

It sounded like you wanted the row on button click, not row hover.

It wad already mentioned, add the row as an attribute of the button, since the row item/index is returned after adding a row.

E.g.(this is pseudo code as i'm on phone)

mybutton=wx.button(mypanel,-1, "btn text")
row=myUlc.append(mybutton)
mybutton.row=row

But this won’t work properly,

Suppose you add 5 buttons (5 rows):

row=myUlc.append(mybutton) (row 1)
row=myUlc.append(mybutton) (row 2)
row=myUlc.append(mybutton) (row 3)
row=myUlc.append(mybutton) (row 4)
row=myUlc.append(mybutton) (row 5)

And suppose when you press the button, it deletes the row which it lives in. If you delete “row 4”, the 5th button will still have row number “5”. And when you press button 5, it will try to delete 5th row but it will fail, because there are 4 rows at that time.

···

On Monday, August 11, 2014 7:10:39 PM UTC+3, Nathan McCorkle wrote:

It wad already mentioned, add the row as an attribute of the button, since the row item/index is returned after adding a row.
E.g.(this is pseudo code as i’m on phone)

mybutton=wx.button(mypanel,-1, “btn text”)
row=myUlc.append(mybutton)
mybutton.row=row

If you need the row numbers to reflect row deletion and insertion
and still map to the correct row you can bind to the insert/delete
events and renumber the affected buttons then call event.skip to
allow the normal processing.

···

On 11/08/14 21:26, steve wrote:

But this won’t work properly,

    Suppose you add 5 buttons (5 rows):



              row=myUlc.append(mybutton) 

(row 1)

      row=myUlc.append(mybutton)  (row 2)

      row=myUlc.append(mybutton)  (row 3)

      row=myUlc.append(mybutton)  (row 4)

      row=myUlc.append(mybutton)  (row 5)



    And suppose when you press the button, it deletes the row which

it lives in. If you delete “row 4”, the 5th button will still
have row number “5”. And when you press button 5, it will try to
delete 5th row but it will fail, because there are 4 rows at
that time.

You could use a linked list then, or whip up an approximation of one, which would update the rest of the buttons.

I had to do something like this a while ago with rows of various widgets in nested sizers... Since I couldn't add a button to a grid easily, and i only needed few rows (but which contained trxtctrl, statictext, radiobuttons, and buttons)

I.e. after (or just before) you delete the row, decrement the values in all the getnextitem (i think there's a method like that)

Hi Steve,

···

On 8/11/2014 22:26, steve wrote:

But this won't work properly,

Maybe time for a MakingSampleApps - wxPyWiki

Werner