Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling a ListView in C#, but still showing the current selection

I have a ListView control, and I'm trying to figure out the easiest/best way to disallow changing the selected row(s), without hiding the selected row(s).

I know there's a HideSelection property, but that only works when the ListView is still enabled (but not focused). I need the selection to be viewable even when the ListView is disabled.

How can I implement this?

like image 223
Blorgbeard Avatar asked Aug 17 '08 23:08

Blorgbeard


2 Answers

You could also make the ListView ownerdraw. You then have complete control over how the items look whether they are selected or not or whether the ListView itself is enabled or not. The DrawListViewItemEventArgs provides a way to ask the ListView to draw individual parts of the item so you only have to draw the bits you're interested in. For example, you can draw the background of the item but leave it up to the ListView to draw the text.

like image 192
Peter Hession Avatar answered Oct 04 '22 02:10

Peter Hession


There are two options, change the selected rows disabled colors. Or change all the other rows to simulate they are disabled except for the selected one. The first option is obviously the easiest, and the second option obviously is going to need some extra protections.

I have actually done the first option before and it works quite well. You just have to remember to change the colors back to the defaults in case another row is selected later on in the process.

like image 25
Nick Berardi Avatar answered Oct 04 '22 01:10

Nick Berardi