Best way to populate a wxListCtrl widget from mysql
Bill Dandreta
wjdandreta at worldnet.att.net
Fri Jul 26 10:26:15 EDT 2002
Hi Arneau,
>What is the best way to populate a wxListCtrl from a Mysql query (may
>return more that one result). I would then Like to select one or more
>from the displayed results and perform another action on them. Any
>help so that I don't waste alot of time going in the wrong direction.
Let me preface my remarks by saying that I am a newbie with wxPython.
I am using Boa Constructor to help me build apps and learn.
I just did what you are trying to do with a wxGrid instead of a
wxListCtrl.
Here are some code snippets to look at:
--SORT THE ROWS FROM QUERY--
self.rows=list(cursor.fetchall())
self.rows.sort(lambda x,y:cmp(x[3],y[3]))
--DISPLAY ROWS UPTO A MAXIMUM OF 10--
for i in range(0,10):
if i>lastrownum:
self.grid1.SetCellValue(i, 0, '')
self.grid1.SetCellValue(i, 1, '')
self.grid1.SetCellValue(i, 2, '')
self.grid1.SetCellValue(i, 3, '')
else:
j=i+self.lastrowdisplayed+1
mfr = self.getmfr(self.rows[j][0])
self.grid1.SetCellValue(i, 0, self.rows[j][0] + '-' + \
self.rows[j][1])
self.grid1.SetCellValue(i, 1, mfr)
self.grid1.SetCellValue(i, 2, self.rows[j][3])
self.grid1.SetCellValue(i, 3, self.rows[j][4])
--EVENT HANDLER FOR LEFT CLICK ON GRIDCELL--
def OnCellLeftClick(self, event):
self.showprices(event.GetRow())
I have not even looked at the wxListCtrl yet so I don't know if it is
a better choice.
Bill
More information about the Python-list
mailing list