Changing cell background inside virtual ListCtrl

Hi everyone!

I have a LC_VIRTUAL ListCtrl and I need to change the background color of “cells” based on their content… What’s the recommended way to do this? Should I switch to UltimateListCtrl and write a custom renderer?

Thanks in advance!

Are you wanting to change the background color for individual cells or entire rows?

···

On Thursday, February 27, 2014 4:54:25 AM UTC-5, Joril wrote:

Hi everyone!

I have a LC_VIRTUAL ListCtrl and I need to change the background color of “cells” based on their content… What’s the recommended way to do this? Should I switch to UltimateListCtrl and write a custom renderer?

Thanks in advance!

Just individual cells, ideally… I’d settle with “entire columns” if it’s possible though :slight_smile:

···

Il giorno lunedì 10 marzo 2014 15:39:28 UTC+1, Mike Stover ha scritto:

Are you wanting to change the background color for individual cells or entire rows?

May be you could try this:

class CustomList(wx.ListCtrl):
    def __init__(self, parent):
        self.attr1 = wx.ListItemAttr()
        self.attr1.SetBackgroundColour("yellow")

        self.attr2 = wx.ListItemAttr()
        self.attr2.SetBackgroundColour("light blue")

    def OnGetItemAttr(self, item):
        if item % 3 == 1:
            return self.attr1
        elif item % 3 == 2:
            return self.attr2
        else:
            return None

I have copied the codes from wx.demo 2.8-unicode.

···

-----
I become to love to write program ever since got in university. The programming languages I have learned from collage lessons are C and Assembly. My interest drive me to learn all the other things. Currently I'm working at Ideal Energy (http://www.idealenergy.com) as a software developer.
My undergraduate degree is Electrical Engineering and Automation. Graduate degree is Power Electronics and Power Drives. Personal favorite programming languages are C, C++, C# and Python.
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Changing-cell-background-inside-virtual-ListCtrl-tp5720303p5720424.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I think that this changes the color of the whole row, I have to change only one cell/column :confused:
Thanks all the same!

···

Il giorno mercoledì 12 marzo 2014 09:55:40 UTC+1, Erxin ha scritto:

May be you could try this:

class CustomList(wx.ListCtrl):

def __init__(self, parent):

    self.attr1 = wx.ListItemAttr()

    self.attr1.SetBackgroundColour("yellow")



    self.attr2 = wx.ListItemAttr()

    self.attr2.SetBackgroundColour("light blue")



def OnGetItemAttr(self, item):

    if item % 3 == 1:

        return self.attr1

    elif item % 3 == 2:

        return self.attr2

    else:

        return None

If you want to change the background color of a column or a single cell why not use grid ctrl? It supply more detail control for each cell’s style.
I think each row of listctrl is design for display a atom data structure. If you insist to use listctrl suggest you transfer your data matrix then add it into the listctrl.

Wish this helpful.

Erxin.

···

Date: Wed, 12 Mar 2014 04:12:20 -0700
From: jorilx@gmail.com
To: wxpython-users@googlegroups.com
Subject: [wxPython-users] Re: Changing cell background inside virtual ListCtrl

Il giorno mercoledì 12 marzo 2014 09:55:40 UTC+1, Erxin ha scritto:

May be you could try this:

class CustomList(wx.ListCtrl):

def __init__(self, parent):

    self.attr1 = wx.ListItemAttr()

    self.attr1.SetBackgroundColour("yellow")



    self.attr2 = wx.ListItemAttr()

    self.attr2.SetBackgroundColour("light blue")



def OnGetItemAttr(self, item):

    if item % 3 == 1:

        return self.attr1

    elif item % 3 == 2:

        return self.attr2

    else:

        return None

I think that this changes the color of the whole row, I have to change only one cell/column :confused:
Thanks all the same!

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

If you want to change the background color of a column or a single cell why not use grid ctrl? It supply more detail control for each cell’s style.

I guess you’re right, but since I already have quite a lot of code relying on a ListCtrl, I’d prefer to stick to it instead of switching to another widget :confused:

I think each row of listctrl is design for display a atom data structure. If you insist to use listctrl suggest you transfer your data matrix then add it into the listctrl.

You mean, converting the list to a non-wx.VIRTUAL one?

···

On Thursday, March 13, 2014 2:39:01 AM UTC+1, 尚尔鑫 wrote:

If you insist to use ListCtrl, I just think out the following several ways.
If any of these make sense then you could try it.

1. For the transfer your data matrix, I means to do a matrix transformation
for your data
data0 = |1 2| to transformed_data =|1 3|
            >3 4| |2 4|

2. Change the column image instead of the column background color to info
something happened.
listctrlObj.SetColumnImage(col, image)
or
listctrlObj.SetItemColumnImage(item, column, image)

3. Check the code detail of ListItem and rewrite the render method. May be
it is the method
listctrlObj.RefreshItem(self, item)

Wish these are helpful.

Erxin

···

-----
I become to love to write program ever since got in university. The programming languages I have learned from collage lessons are C and Assembly. My interest drive me to learn all the other things. Currently I'm working at Ideal Energy (http://www.idealenergy.com) as a software developer.
My undergraduate degree is Electrical Engineering and Automation. Graduate degree is Power Electronics and Power Drives. Personal favorite programming languages are C, C++, C# and Python.
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Changing-cell-background-inside-virtual-ListCtrl-tp5720303p5720443.html
Sent from the wxPython-users mailing list archive at Nabble.com.