ListCtrl without icons

I feel like this is a dumb issue, but I can’t figure it out.

I’m using Python 3.7 and wxPython 4.1.1a1, the first daily build following the 4.1.0 release on Windows 10 and MacOS 10.15.

I have a ListCtrl with the ColumnSorterMixin. I need to assign an ImageList so the ColumnSorter can show whether my columns are sorted ascending or descending.

My ListCtrl shows my first sort order image on each line in the ListCtrl. I can’t figure out how to make that image go away without losing my column sort indicators.

Sure, if I don’t call SetImageList(), I don’t get the image in the ListCtrl, but then I don’t get the sorter images in my columns.

I’ve tried using the following:

    self.resultsList.InsertColumn(0, _("Word"))
    self.resultsList.InsertColumn(1, _("Frequency"), wx.LIST_FORMAT_RIGHT)
    self.resultsList.InsertColumn(2, _("Word Group"))

I thought that would not show images, but there they are. I’ve tried using:

    info = wx.ListItem()
    info.Image = -1
    info.Mask = wx.LIST_MASK_TEXT
    info.Text = _("Word")
    self.resultsList.InsertColumn(0, info)
    self.resultsList.InsertColumn(1, _("Frequency"), wx.LIST_FORMAT_RIGHT)
    self.resultsList.InsertColumn(2, _("Word Group"))

I thought leaving images out of the mask might work. No luck. I still get the first image from the ImageList on each line in the ListCtrl.

I’ve tried messing with the ListCtrl demo along the lines above and can’t get rid of the happy little images there without losing the column sort images.

It would be fantastic if someone can tell me what I’m doing wrong and help me get rid of the images I don’t want and as far as I can tell don’t ask for.

Thanks in advance,
David

Hi Thom,

  This made the entire first column disappear, including the text. 

I suppose I could add an additional column too. I was hoping for
an easier way.

  I've also been playing with inserting a non-visible image, but

that leaves an empty space in the column that I’d rather avoid.

David

Sorry David, that’s why I just revoked my previous reply…
I’m at this very moment looking for a solution. Bear with me

David,
Please, attach your current source code here and I’ll dig into it.
Thom

Thom,

Thanks for looking into this.

  I've been using the wxPython Demo's ListCtrl demo as my simple

example. You can mess with the PopulateList() method at line 163
to manipulate list item creation. I thought the info.Mask
definition would be the key, but it doesn’t seem to make a
difference.

David

YW, waiting for attachment… :innocent:

David,

I knew I once hit this same “trap” you’re hitting now.
Have it documented. See attached my TaskBrowserListCtrl class as an example for you to cross the bridge.

ForDavidWoods - derived ListCtrl class example.py (2.4 KB)

You’ll find the key in line 34 of the snippet:
idx = self.InsertItem(key, tsk[1:], -1) # -1 prevents image in column 1

Good luck!

Thom

There is no attachment. Like I said, the wxPython Demo’s
ListCtrl example is the simple code I’ve been using to try to
combine no images in a ListCtrl with images required for the
ColumnSorterMixin. It’s at
. The demo gives
nice tools for modifying the examples, and it avoids the
possibility of my introducing issues with my own code.

  I see your example just came in.  I'll take a good look at it. 

Thanks again.

David

Thom,

  Cool.  That trick works in the demo.  There's a bit of empty

space on each line that I’d prefer wasn’t there, but I can make my
Ascending and Descending images skinnier and can make this work.

David

Congrats and enjoy

For the record: The native list view widget on Windows assumes that if there is an image list then you must want there to be an image on each list item, and so it defaults to making space for it and using the first image in the list if none are specified. Apparently Microsoft doesn’t expect that anybody would want to have a list view without icons on the items.

Thanks for the -1 hint @Thom , I had forgotten about that.

Cheers Robin, thanks for the clear extra info. Bummer for MS.
Took me a little digging to find the -1, too … I encountered it 3 years ago.