-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathThreeStateTreeView.cs
More file actions
80 lines (75 loc) · 3.06 KB
/
Copy pathThreeStateTreeView.cs
File metadata and controls
80 lines (75 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
namespace Ascentium.Research.Windows.Forms.Components
{
/// <summary>
/// ThreeStateTreeNode inherits from <see cref="http://msdn2.microsoft.com/en-us/library/sc9ba94b(vs.80).aspx">TreeView</see>
/// and adds the ability to cascade state changes to related nodes, i.e. child nodes and or parent nodes, as well as to optionally
/// use the three state functionality.
/// </summary>
public class ThreeStateTreeView : TreeView
{
#region Constructors
/// <summary>
/// Initializes a new instance of the ThreeStateTreeView class in addition to intializing
/// the base class (<see cref="http://msdn2.microsoft.com/en-us/library/system.windows.forms.treeview.treeview(VS.80).aspx">TreeView Constructor</see>).
/// </summary>
public ThreeStateTreeView() : base()
{
}
#endregion
#region Public Properties
/// <summary>
/// Flag. If true, use three state checkboxes, otherwise, use the default behavior of the TreeView and associated TreeNodes.
/// </summary>
private bool mUseThreeStateCheckBoxes = true;
[Category("Three State TreeView"),
Description("Flag. If true, use three state checkboxes, otherwise, use the default behavior of the TreeView and associated TreeNodes."),
DefaultValue(true),
TypeConverter(typeof(bool)),
Editor("System.Boolean", typeof(bool))]
public bool UseThreeStateCheckBoxes
{
get { return this.mUseThreeStateCheckBoxes; }
set { this.mUseThreeStateCheckBoxes = value; }
}
#endregion
#region Overrides
/// <summary>
/// Raises the AfterCheck event.
/// </summary>
/// <param name="e">A <see cref="http://msdn2.microsoft.com/en-us/library/system.windows.forms.treevieweventargs.aspx">TreeViewEventArgs</see> containing the event data.</param>
protected override void OnAfterCheck(TreeViewEventArgs e)
{
base.OnAfterCheck(e);
if (this.UseThreeStateCheckBoxes)
{
switch (e.Action)
{
case TreeViewAction.ByKeyboard:
case TreeViewAction.ByMouse:
{
if (e.Node is ThreeStateTreeNode)
{
// Toggle to the next state.
ThreeStateTreeNode tn = e.Node as ThreeStateTreeNode;
tn.Toggle();
}
break;
}
case TreeViewAction.Collapse:
case TreeViewAction.Expand:
case TreeViewAction.Unknown:
default:
{
// Do nothing.
break;
}
}
}
}
#endregion
}
}