public void CleanTree(NTree <List <object> > node)
 {
     foreach (NTree <List <object> > child in node.Children)
     {
         CleanTree(child);
         if (child.Data != null && child.Data.Count == 1 && child.Children.Count == 1)
         {
             node.DeleteChild(child);
             node.AddChild(child.Children.First.Value);
             break;
         }
     }
 }
        private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string previousSelecteIndex = ((ComboBoxCondition)sender).Index;
            string newSelectedIndex     = ((ComboBox)sender).SelectedItem.ToString();

            if (previousSelecteIndex != newSelectedIndex)
            {
                if ((string)Tree.Data[0] == newSelectedIndex)
                {
                    Tree.AddChildData(null);
                }
                else if ((string)Tree.Data[0] == "")
                {
                    ((ComboBoxCondition)sender).ParentNode.Data = new List <object>(new object[] { newSelectedIndex });
                    ((ComboBoxCondition)sender).ParentNode.AddChildData(null);
                }
                else
                {
                    if (TreeContainsAndOr(Tree, newSelectedIndex))
                    {
                        if (((ComboBoxCondition)sender).ParentNode.Data.Count == 1 && (string)((ComboBoxCondition)sender).ParentNode.Data[0] == newSelectedIndex)
                        {
                            ((ComboBoxCondition)sender).ParentNode.AddChildData(null);
                        }
                        else
                        {
                            List <object> previousData = ((ComboBoxCondition)sender).Node.Data;
                            ((ComboBoxCondition)sender).Node.Data = new List <object>(new object[] { newSelectedIndex });
                            ((ComboBoxCondition)sender).Node.AddChildData(previousData);
                            ((ComboBoxCondition)sender).Node.AddChildData(null);
                        }
                    }
                    else
                    {
                        NTree <List <object> > previousTree = Tree;
                        Tree = new NTree <List <object> >(new List <object>(new object[] { newSelectedIndex }));
                        Tree.AddChild(previousTree);
                        Tree.AddChildData(null);
                    }
                }

                GeneratePanel();
            }
        }