I'm using Phillip Piper's ObjectListView wrapper, specifically, a TreeListView
My TreeListView:
- Checkboxes: True
- CheckedAspectName: {name of bool? property in my model)
- HierarchicalCheckboxes: True
- TriStateCheckboxes: true
- View: Details
I set TriStateCheckboxes to True because I want my TreeListView to be able to display the indeterminate symbol in the TreeListView’s checkboxes. However, I don't want the user to ever be able to explicitly set a checkbox to an indeterminate value. Rather, when a user clicks on a checkbox, I want it to toggle only between checked and unchecked. If a branch checkbox and all its children’s checkboxes are checked, and the children's checkboxes transition to a mix of checked and unchecked, I want the branch’s checkbox to show the indeterminate symbol.
In other words, the indeterminate state is ever only to be asserted programmatically and then only on a branch when the checkboxes of the branch’s children are not solely all checked or not solely all unchecked.
Realizing that a tristate checkbox cycles: checked, indeterminate, unchecked, I tried forcing an indeterminate state to an unchecked state when the user clicks on a checked checkbox, but that didn’t work, i.e., the checkbox state in the TreeListView remains unchanged after executing my ObjTreeListViewPreview_ItemChecked code.
Note: the class ClsTreeListViewPreview derives from TreeListView
private void ObjTreeListViewPreview_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ClsTreeListViewPreview objTreeListViewPreview = (ClsTreeListViewPreview)sender;
if (objTreeListViewPreview.MouseMoveHitTest.Item.CheckState == CheckState.Indeterminate)
{
objTreeListViewPreview.MouseMoveHitTest.Item.CheckState = CheckState.Unchecked;
}
}
Is what I want possible with a TreeListView that has tristate and hierarchical checkboxes ? If so, which delegates and methods are necessary?
I have a Winforms
TreeListViewwithtristate checkboxesworking where theindeterminatesetting is denied to the user. Theindeterminatesetting appears in a checkbox only when the user sets the checkbox's child objects to a mix of checked and unchecked.HierarchicalCheckboxesare not used. All checkbox settings are managed manually.It uses a CheckStatePutter, an ItemChecked event handler, and a HeaderCheckBoxChanging event handler (when a header checkbox is used) to manually manage checkbox settings
Demo code follows
Code is self-contained (except for the
ObjectListView.dll). Create a Winforms project with an empty form and copy/paste the two classes belowMain form
Class ClsTriStateTreeListView