I have a wx.ListCtr:
self.resultList = wx.ListCtrl(self.rightPanel, -1, style=wx.LC_REPORT | wx.EXPAND)
f = self.GetFont()
dc = wx.WindowDC(self)
dc.SetFont(f)
i = 0
for items in (SEARCHPARAMS):
self.resultList.InsertColumn(i,items)
width, height = dc.GetTextExtent(items)
self.resultList.SetColumnWidth(i, width)
i +=1
I'd like to populate the ListCtrl from a dictionaries contained within an object list.
I can 'manually' enter the values across:
def populateResultList(self, dataList, headers):
first = True
for items in dataList:
if first:
self.resultList.InsertStringItem(i, items.dictionary[headers[0]])
first = False
self.resultList.SetStringItem(0, 1, items.dictionary[headers[1]])
self.resultList.SetStringItem(0, 2, items.dictionary[headers[2]])
self.resultList.SetStringItem(0, 3, items.dictionary[headers[3]])
self.resultList.SetStringItem(0, 4, items.dictionary[headers[4]])
Or I could fill each column down:
i = 0
for items in dataList:
self.resultList.InsertStringItem(i, items.dictionary[headers[0]])
self.resultList.SetStringItem(i, 1, items.dictionary[headers[1]])
self.resultList.SetStringItem(i, 2, items.dictionary[headers[2]])
i +=1
But since my program reads from a CSV file and dynamically creates the columns and column headers - I not sure how to write a method to populate the wx.ListCtrl dynamically as well (instead of specifying line by line which colum to write to)