Disabling ListView in C # but showing current selection

I have a ListView control, and I'm trying to figure out the easiest / best way to prevent the selected rows from being modified without hiding the selected rows.

I know there is a HideSelection property, but it only works when the ListView is still on (but not focused). I need a choice to view, even if the ListView is disabled.

How to implement this?

+7
c # listview winforms
source share
3 answers

You can also create a ListView ownerdraw. Then you have full control over how the elements look regardless of whether they are selected or not or whether the ListView itself is enabled or not. DrawListViewItemEventArgs provides a way to request a ListView to draw individual parts of an element, so you only need to draw the bits of interest to you. For example, you can draw the background of an element, but leave it in the ListView to draw text.

+2
source share

There are two options, changing the selected lines of disabled colors. Or change all other lines to simulate, they are disabled, except for the selected one. The first option is obviously the simplest, and the second option will obviously require additional protection.

I really made the first option before, and it works very well. You just need to remember to change the colors to the default values ​​if another line is selected in the process.

+1
source share

Deploy SelectedIndexChanged and do it

  private void listViewABC_SelectedIndexChanged(object sender, EventArgs e) { listViewABC.SelectedItems.Clear(); } 
0
source share

All Articles