private void addTreeComponent(CommadnTreeComponent c) { if (c.Level > 1) { List <int> path = new List <int>(); //path.Insert(0, c.Position); CommadnTreeComponent tmp = FindById(c.Comand.ParentID, commandTreeComponentList); while (tmp != null) { path.Insert(0, FindById(tmp.Comand.Id, commandTreeComponentList).Position); tmp = FindById(tmp.Comand.ParentID, commandTreeComponentList); } path.Insert(0, 0); var nodes = CommandsTree.Nodes; for (int i = 0; i < path.Count; i++) { nodes = nodes[path[i]].Nodes; } nodes.Add(c.Comand.Text).Name = c.Comand.Id; } else { CommandsTree.Nodes[0].Nodes.Add(c.Comand.Text).Name = c.Comand.Id; } }
private void button1_Click(object sender, EventArgs e) { String id = CommandsTree.SelectedNode.Name; Comand c = new Comand(FindSuitableId(), messageTextBox.Text, "", id, Convert.ToString(typeComboBox.SelectedIndex + 1)); CommadnTreeComponent ct = new CommadnTreeComponent(c, 2, 0); commandTreeComponentList.Add(ct); DBClass.putComand(ct.Comand); CommandsTree.BeginUpdate(); addTreeComponent(ct); CommandsTree.EndUpdate(); setAddComponets(false); }
private CommadnTreeComponent FindById(String id, List <CommadnTreeComponent> list) { CommadnTreeComponent commandNode = null; foreach (CommadnTreeComponent c in list) { if (c.Comand.Id == id) { commandNode = c; break; } } return(commandNode); }
private void fillTree(CommadnTreeComponent c, List <CommadnTreeComponent> list) { if (c.Comand.ChildrID != null) { String[] ids = c.Comand.ChildrID.Split(';'); for (int i = 0; i < ids.Length; i++) { CommadnTreeComponent kid = new CommadnTreeComponent(DBClass.getComand(ids[i]), c.Level + 1, i); if (kid.Comand != null) { list.Add(kid); fillTree(kid, list); } } } }