I’ve got a program made basically from a ListCtrl and has an add button, an edit button and an delete button. As you can imagine, is not very difficult (I think is difficult because is different from lineal programming, but I’m learning).
The data displayed is taken from a database, and some data is added, or edited, or deleted depending on the situation.
I’d like now that, when data is changed, the ListCtrl reloads completely (basically, because of data is sorted). This means: update data from database, and then make a new ListCtrl from the database with the new data, not update separately ListCtrl and database.
This is the code that inserts data into ListCtrl, and is in a Panel (the object that should reload ListCtrl is a Dialog, which is called from various places):
i = 0
for data in coches:
index = self.lista.InsertStringItem(i, data[0])
self.lista.SetStringItem(index, 1, str(data[1]))
self.lista.SetStringItem(index, 2, str(data[2]))
self.lista.SetStringItem(index, 3, str(data[3]))
self.lista.SetStringItem(index, 4, str(data[4]))
if((index+1) % 2 == 0):
self.lista.SetItemBackgroundColour(index,gris)
i += 1
“coches” is a list from the database and “self.lista” is the ListCtrl object
Thanks in advance
Not sure of what the problem is, but you should put your code for filling the
ListCtrlinside a method and call it whenever you modify the data in order to update the list.To clear the list before filling it again you can use
ListCtrlmethodsDeleteAllItems()orClearAll().