ListCtrl Column Lines (3.0.2.0 vs 4.1.1)

I am porting another project from Python27 to 37 & have found a difference between the handling of the ListCtrl ItemBackground colouring. (Windows 10)

With the same code, the ListCtrl is displayed slightly differently with thick white column lines on wx 4.1.1.

ListCtrl (2.7.15) ListCtrl (3.7.9)

Whilst this is only a cosmetic change, I would like to understand how to control this behaviour.

I have read in some comments from Robin that wx4 uses the “system theme style” on windows & to disable this function I could use self.MylistCtrl.EnableSystemTheme(False) but this doesnt seem to make any difference.

In the documentation there are the style wx.LC_HRULES ¦ wx.LC_VRULES to add line separation.

Could it be that wx.LC_HRULES is enabled by default with wx.LC_REPORT?
Is there a simple way to remove the column lines?

Short code example:

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MyFrame, self).__init__(parent, title=title, size=(275, 150))

        # Create a panel and a list control
        panel = wx.Panel(self)
        self.myListCtrl = wx.ListCtrl(panel, style=wx.LC_REPORT)
        self.myListCtrl.EnableSystemTheme(False)  # Remove this line for Python 2.7

        # Add three columns to the list control
        self.myListCtrl.InsertColumn(0, "Name")
        self.myListCtrl.InsertColumn(1, "Age")
        self.myListCtrl.InsertColumn(2, "Gender")

        # Add some items to the list control
        self.myListCtrl.Append(["Alice", "25", "Female"])
        self.myListCtrl.Append(["Bob", "30", "Male"])
        self.myListCtrl.Append(["Charlie", "35", "Male"])
        self.myListCtrl.Append(["Dave", "30", "Female"])

        for row in range(self.myListCtrl.GetItemCount()):
            if row % 2 == 0:
                self.myListCtrl.SetItemBackgroundColour(row, "green")
            else:
                self.myListCtrl.SetItemBackgroundColour(row, "red")

        # Create a box sizer to layout the panel and the list control
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.myListCtrl, 1, wx.EXPAND)
        panel.SetSizer(sizer)

        self.Show()

app = wx.App()
MyFrame(None, "List Control Example")
app.MainLoop()

Thanks in advance for any ideas,

Gabbo

I don’t have Windows to test on but, according to the docs, you have to use a 2-phase create pattern in order to utilise EnableSystemTheme().

# This creates the object, but not the window
widget = wx.ListCtrl()

# Disable the system theme
widget.EnableSystemTheme(False)

# Now create the window
widget.Create(parent, wx.ID_ANY)
1 Like

Hello @RichardT thanks for your reply.
You are indeed correct, with the following modification to the code, the display is the same as the previous wx version…

self.myListCtrl = wx.ListCtrl()
self.myListCtrl.EnableSystemTheme(False)
self.myListCtrl.Create(panel, style=wx.LC_REPORT)

Thanks a lot…
Must study the documentation more thoroughly next time… :man_facepalming:

Gabbo