How to determine row position in a list box

Scott Holmes scottholmes at
Tue Aug 5 19:45:26 CEST 2003

Daniel P. Engel wrote:
> Wouldn't that be sels[0]?

The value in sels[0] is the string I wish to display in a label, not the 
row number.  Actually I've abandoned the attempt to find the row number. 
  I'm now creating a dictionary at the same time the listbox is being 

         while 1:
           lRec = curs.fetchone()
           if not lRec: break

           itm = str(lRec[3]) + ", " + str(lRec[1]) + " " + str(lRec[2])
 'end', itm)
           self.pnmbrs[itm] = str(lRec[0])

The select statement fetches the unique people_nmbr and the person's 
first middle and last name.  The listbox displays the name value, 
thusly:  last_name, first_name middle_name.
When a row is selected from the listbox, the selected value is used as a 

     def selectionCommand(self):
         sels =
         if len(sels) == 0:
             print 'No selection'
             print 'Selection:', sels[0]
             print 'People Number:', self.pnmbrs[sels[0]]

If there is a prefered or more efficient way of doing this, I would be 
grateful to hear of it.

Scott Holmes         
                                scottholmes at

   Independent Programmer/Analyst                  Passport 4GL
   PHP HTML Composer                PostgreSQL     Informix 4GL, SQL
       There are more things in heaven and earth, Horatio,
              than are dreamt of in your philosophy

More information about the Python-list mailing list