private void myTreeView_AfterCheck(object sender, TreeViewEventArgs e)
{
if (trvCheckLock)
{
return;
}
trvCheckLock = true;
trvMessageType.BeginUpdate();
try
{
TreeNode item = e.Node;
//If the user checks/unchecks the node that has children,
if (item.Nodes.Count > 0)
{
//All children are unchecked as well
foreach (TreeNode child in item.Nodes)
{
child.Checked = item.Checked;
UpdateObjectModel(item.Text, child.Text, child.Checked);
}
}
//Otherwise (if the item has a parent)
if (item.Parent != null)
{
//The parent node should be checked only when all its children
//are checked too
if (!item.Checked)
{
item.Parent.Checked = false;
}
else
{
bool allChecked = true;
foreach (TreeNode sibling in item.Parent.Nodes)
{
if (!(allChecked = allChecked && sibling.Checked))
{
break;
}
}
item.Parent.Checked = allChecked;
}
}
//Update the list of the selected items to the right
if (item.Parent != null)
UpdateSelected(item);
}
finally
{
trvMessageType.EndUpdate();
trvCheckLock = false;
}
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.