how to get the index of selected control?

The above code is basically what Robin gave you and he posted a link from where it came, i.e. it is a method in the sizer code.

If you want the same functionality outside the sizer (i.e. "self" is no longer pointing to a sizer) then you need to adapt it a little bit.

See attached.

Werner

scrollpanel.py (2.31 KB)

···

On 10/28/2011 06:59 AM, Wonjun, Choi wrote:

I tested below code. but how can I get the index of selected control
in Sizer?

     def GetItemIndex(self, item):
         sItem = self.Autosizer.GetItem(item)<-------- this will bring
the controls in Autosizer
         assert sItem is not None, "Item not found in the sizer."
         allItems = self.Children<----------- this will bring the
controls in TestPanel
         idx = 0
         for i in allItems:
             print "items : %s"%i.this
             print "selected : %s"%sItem.this
             if i.this == sItem.this:<-------------- when debugging
time, the code skips here.
                 break
             idx += 1
         return idx

I make like this:

def GetItemIndex(self, item):

print ‘GetItemIndex: %s, %s’ % (item, type(item))

    sItem = self.Autosizer.GetItem(item)
    assert sItem is not None, "Item not found in the sizer."
    allItems = self.Autosizer.GetChildren()

    idx = 0
    for i in allItems:
        if i.this == sItem.this:
            break
        idx += 1
    return idx

always thank you.

Wonjun, Choi

···

2011/10/28 werner wbruhin@free.fr

On 10/28/2011 06:59 AM, Wonjun, Choi wrote:

I tested below code. but how can I get the index of selected control

in Sizer?

 def GetItemIndex(self, item):

     sItem = self.Autosizer.GetItem(item)<-------- this will bring

the controls in Autosizer

     assert sItem is not None, "Item not found in the sizer."

     allItems = self.Children<----------- this will bring the

controls in TestPanel

     idx = 0

     for i in allItems:

         print "items : %s"%i.this

         print "selected : %s"%sItem.this

         if i.this == sItem.this:<-------------- when debugging

time, the code skips here.

             break

         idx += 1

     return idx

The above code is basically what Robin gave you and he posted a link from where it came, i.e. it is a method in the sizer code.

If you want the same functionality outside the sizer (i.e. “self” is no longer pointing to a sizer) then you need to adapt it a little bit.

See attached.

Werner

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en