C# – Is it possible to set a checked listview item to mixed state

.netc++checkboxcheckedlistboxlistview

The CheckBox control exposes both boolean Checked and System.Windows.Forms.CheckState enum CheckState properties, which allow you to set the control to either checked, unchecked, or mixed state (Indeterminate enum value).

I want to set a ListView item's state to Indeterminate, but only the Checked property seems to be available. So, is there a way to set it to mixed, possibly by window messaging or similar tricks?

Best Solution

Well, you can use the following workaround:

  1. Create state ImageList with 3 states (you can take create images using CheckBoxRenderer)
  2. Assign this image list to list view
  3. Then you need to handle OnMouseDown (or OnMouseClick) and OnKeyDown events and shift state images for needed list item

Of course you also need to write several helper methods to get checked state, etc. But in general this solution is relatively easy to implement.

Actually internal ListView implementation do the same, but this logic is hidden inside comctl32.dll.

Related Question