views:

391

answers:

3

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?

A: 

ListView does not have indeterminate state.

J-16 SDiZ
I know it's not an exposed property in the Windows Forms control; I'm asking if it's possible any other way.
Factor Mystic
+1  A: 

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.

arbiter
This is from awhile ago, but I guess I forgot to accept this answer.I ended up rolling my own control according to this process, and put it in my BSD licensed Aero.Control pack: http://factormystic.net/projects/code/aero.controls
Factor Mystic
A: 

ObjectListView (an open source wrapper around .NET WinForms ListView) supports check boxes with mixed state.

Have a look at the Simple tab of the demo to see them in action.

(Having done the work, I have to say that it is not as easy as arbiter suggests)

Grammarian