How to determine row position in a list box

Scott Holmes scottholmes at sbcglobal.net
Tue Aug 5 13:45:26 EDT 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 
populated:

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

           itm = str(lRec[3]) + ", " + str(lRec[1]) + " " + str(lRec[2])
           self.box.insert('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 
key:

     def selectionCommand(self):
         sels = self.box.getcurselection()
         if len(sels) == 0:
             print 'No selection'
         else:
             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                   http://sholmes.ws
                                http://pages.sbcglobal.net/scottholmes
                                scottholmes at sbcglobal.net

   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