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,
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:
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.
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,
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.
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)
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)