public void DeleteCriteria()
{
TreeNode SelectedNode = ConditionTree.SelectedNode;
// Make sure we have a node selected
if (SelectedNode == null)
{
MessageBox.Show("Please select a criteria to edit.");
return;
}
// Make sure we can't delete the parent node
// Mostly because we need to keep references intact
if (SelectedNode.Parent == null) return;
// Dont delete on Plus / Div Trees
if (!(SelectedNode.Tag is ConditionList))
{
TreeNode Parent = SelectedNode.Parent;
if (Parent == null)
return;
// If we are in the root condition list
if (Parent.Parent == null || Parent.Parent.Tag == null)
{
ConditionTree.Nodes.Remove(SelectedNode);
return;
}
// Get the parents condition list
ConditionList C = (ConditionList)Parent.Tag;
// Remove the whole tree if its a not statement
if (C.Type == ConditionType.Not)
ConditionTree.Nodes.Remove(Parent);
// We donot handle nested condition lists in this form
else if (C.Type == ConditionType.Plus || C.Type == ConditionType.Div)
{
ConditionTree.SelectedNode = Parent;
EditCriteria();
}
else
{
ConditionTree.Nodes.Remove(SelectedNode);
}
}
else
ConditionTree.Nodes.Remove(SelectedNode);
ConditionTree.Refresh();
}