I have an application where the lines in a listctrl are coloured in a zebra way. I use the following code:
def SetBackgroundLines(self):
n = 0
i = self.GetTopItem()
while n < self.GetItemCount():
i = self.GetNextItem(i)
if i < 0:
break
if i % 2 == 1:
self.SetItemBackgroundColour(i,self.bgcolour)
else:
self.SetItemBackgroundColour(i, self.stdcolour)
self.RefreshItem(i)
n += 1
self.Refresh()
This works OK the first time. Shows nicely.
However when an item is added to the list (appended) and the list is sorted, the itemnumbers do not change hence the order of processing does not change which leads to a wrong backgroundcolour (see the added screenshot). I simply don’t know how to read the listitems in the order that they are displayed.
Am Dienstag, 17. Dezember 2013 17:24:34 UTC+1 schrieb Dick Kniep:
Hi list,
I have an application where the lines in a listctrl are coloured in a zebra way. I use the following code:
def SetBackgroundLines(self):
n = 0
i = self.GetTopItem()
while n < self.GetItemCount():
i = self.GetNextItem(i)
if i < 0:
break
if i % 2 == 1:
self.SetItemBackgroundColour(i,self.bgcolour)
else:
self.SetItemBackgroundColour(i, self.stdcolour)
self.RefreshItem(i)
n += 1
self.Refresh()
This works OK the first time. Shows nicely.
However when an item is added to the list (appended) and the list is sorted, the itemnumbers do not change hence the order of processing does not change which leads to a wrong backgroundcolour (see the added screenshot). I simply don’t know how to read the listitems in the order that they are displayed.
Thanks for the answer. This works nicely for regular lists. However, I am using a virtual list and with that list, ListRowHighlighter-mixin does not seem to work. Or do I need to do something special?
···
Op dinsdag 17 december 2013 17:24:34 UTC+1 schreef Dick Kniep:
Hi list,
I have an application where the lines in a listctrl are coloured in a zebra way. I use the following code:
def SetBackgroundLines(self):
n = 0
i = self.GetTopItem()
while n < self.GetItemCount():
i = self.GetNextItem(i)
if i < 0:
break
if i % 2 == 1:
self.SetItemBackgroundColour(i,self.bgcolour)
else:
self.SetItemBackgroundColour(i, self.stdcolour)
self.RefreshItem(i)
n += 1
self.Refresh()
This works OK the first time. Shows nicely.
However when an item is added to the list (appended) and the list is sorted, the itemnumbers do not change hence the order of processing does not change which leads to a wrong backgroundcolour (see the added screenshot). I simply don’t know how to read the listitems in the order that they are displayed.
However when an item is added to the list (appended) and the list is sorted, the itemnumbers do not change hence the order of processing does not change which leads to a wrong backgroundcolour (see the added screenshot). I simply don't know how to read the listitems in the order that they are displayed.
Thanks for the answer. This works nicely for regular lists. However, I am using a virtual list and with that list, ListRowHighlighter-mixin does not seem to work. Or do I need to do something special?
I haven’t used virtual listctrl. But reading the docs i think you need to implement ListCtrl.OnGetItemAttr and return a ListItemAttr with the backgroundcolor set depending on the item.
I have solved the problem now, so I thank you both for your valuable answers.
Cheers and I wish you well in 2014
D.Kniep
···
Op woensdag 18 december 2013 11:40:01 UTC+1 schreef Torsten:
Thanks for the answer. This works nicely for regular lists. However, I am using a virtual list and with that list, ListRowHighlighter-mixin does not seem to work. Or do I need to do something special?
I haven’t used virtual listctrl. But reading the docs i think you need to implement ListCtrl.OnGetItemAttr and return a ListItemAttr with the backgroundcolor set depending on the item.