Fog Creek Software
g
Discussion Board




ListView, WIN API, coloring

I may be missing something incredibly obvious, if I am, please point me in the right direction:

C++ app, Win 32, API - no MFC, ATL, WTL etc

It contains a dialog with a ListView control.  The list view is in Report Mode (n.b. I mean ListView like MFC's CListCtrl, etc. - **not** ListBox)

How do you change the background of a particular row/column (i.e. just one cell) in the ListView - short of ownerdrawing *everything*?

S. Tanna
Wednesday, February 4, 2004

Ownerdraw everything.

Joel Spolsky
Fog Creek Software
Wednesday, February 4, 2004

(I don't mean to be glib. You're really not missing anything, and this is why there are so many successful third-party components you can buy that improve on the listview).

Joel Spolsky
Fog Creek Software
Wednesday, February 4, 2004

Darn, I thought so.

But it's a pain, cos I can't use any of my spiffy flicker-free, CListCtrl derivative, MFC-based classes

S. Tanna
Wednesday, February 4, 2004

We post our 2nd comments at the same time.

I know glibness not intended


This code runs inside a DLL inside another (extensible) app, so I don't want to go off and use some OCX, etc. as there are too many things likely to break.

S. Tanna
Wednesday, February 4, 2004

Google for CustomDraw. It's like OwnerDraw, but allows you to customize the ListView control cell by cell. Might be what you're looking for.

Floridian
Wednesday, February 4, 2004

Here's another vote for Custom Draw.  It lets you hook into the drawing process without having to take the entire thing over.  You probably just want to handle the item prepaint event and change the background color at that point.  Do a search for NM_CUSTOMDRAW for more info.

SomeBody
Wednesday, February 4, 2004

NM_CUSTOMDRAW folks, thanx

I have it working

Used this MFC example for inspiration:
http://www.codeproject.com/listctrl/lvcustomdraw.asp

To convert to WinAPI, just remember SetWindowLong( HWND, DWL_MSGRESULT, xx ) is method to set the LRESULT return in a dialog box callback function, I didn't at first.

S. Tanna
Wednesday, February 4, 2004

P.S.
Probable windows bug

Listview, full row selection, and single selection
NM_CUSTOMDRAW to set the background (for last column)
Window color is NOT white (GetSysColor)

Select an item, then select something else

If cell is empty, it leaves behind a trail of the selection

Quick'n'dirty work round - even in empty cells put a space character

S. Tanna
Wednesday, February 4, 2004

*  Recent Topics

*  Fog Creek Home