views:

498

answers:

3

Is it possible to override the listview detault selection paint? The one that looks semi-transparent blue overlayed over the items, like in the explorer windows.

I want to draw an outline around the selection to indicate selection.

Any way to do this? Examples are appreciated.

+1  A: 

My first thought would be to subclass the ListView control, set OwnerDraw to true and perform all of the drawing yourself, but that seems like overkill for such a small change.

However, in my wanderings of the web I found this article, which may be helpful, as it's very similar to your situation and allows you to avoid drawing everything yourself.

Dustin Hoffman
Thanks, will give it a try. Surprised this is how it's done for a small thing as this. Winforms doesn't seem very flexible with these kind of customizations I guess.
Joan Venge
+1  A: 
Stan R.
Thanks Stan, I will try this when I get home. Thanks very much for your code example.
Joan Venge
I just tried it, but the ProcessDrawItem is never called. I put a breakpoint, it wasn't hit. I use win7 if that would be a problem?
Joan Venge
i am not sure if it would behave the same way on win7, i don't see why not. Also I know this is silly but did you change the type from ListView to CustomListView in the designer part of the class. Remember the constructor calls InitializeComponent() in which it creates the ListView, if you added a listview from the toolbar you're going to have to change it to CustomListView in the code.
Stan R.
The Form constructor that is...
Stan R.
A: 
Grammarian
Thanks, your control looks cool. Is it commercial? Not nitpicking, just wondering.
Joan Venge
It's open source and GPL'ed. If a company doesn't like the GPL, they can buy a commercial license for a couple of hundred dollars (less for small companies/individuals).
Grammarian
Also, it really just a .NET ListView, but with lots of clever helper functions that take away the pain of using the plain vanilla version.
Grammarian