protected Node AddChild(Node parent, string text) { Node node = new AdvancedTreeNode(text); parent.Nodes.Add(node); return(node); }
private void AutoSelectChildren(AdvancedTreeNode node, bool value) { if (node != null && node.Checked != value) { node.Checked = value; } if (node.Nodes != null && node.Nodes.Count > 0) { node.Nodes.ToList().ForEach(x => AutoSelectChildren((AdvancedTreeNode)x, value)); } var item = _questions.FirstOrDefault(i => i.Title == node.Text); if (item != null) { if (value) { if (!_selectedQuestions.Contains(item)) { _selectedQuestions.Add(item); } } else { _selectedQuestions.Remove(item); } } }
protected Node AddRoot(string text) { Node node = new AdvancedTreeNode(text); TreeModel.Nodes.Add(node); return(node); }
private void AutoSelectChildren(AdvancedTreeNode node, bool value) { if (node != null && node.Checked != value) { node.Checked = value; } if (node != null && (node.Nodes != null && node.Nodes.Count > 0)) { node.Nodes.ToList().ForEach(x => AutoSelectChildren((AdvancedTreeNode)x, value)); } AddOrRemoveSelectedQuestion(node, value); }
public void InitControl(SqlConnectionStringBuilder conn, string schema) { groupBox1.Controls.Clear(); TableBusiness tableBusiness = new TableBusiness(); try { List <Table> lstTable = tableBusiness.ListTables(conn, schema); TreeView tree = new TreeView(); tree.ImageList = lstImage; tree.Name = "tvTables"; tree.CheckBoxes = true; tree.AfterCheck += new TreeViewEventHandler(tree_AfterCheck); tree.Dock = DockStyle.Fill; AdvancedTreeNode node; AdvancedTreeNode nodeSon; foreach (Table table in lstTable) { node = new AdvancedTreeNode(); node.Checked = true; node.Text = table.Name; node.Value = table; node.SelectedImageIndex = (int)DBImage.TABLE; node.ImageIndex = (int)DBImage.TABLE; tree.Nodes.Add(node); foreach (Column column in table.Columns) { nodeSon = new AdvancedTreeNode(); nodeSon.Checked = true; nodeSon.Text = column.Name + " (" + ListarAtributos(column) + ")"; nodeSon.Value = column; nodeSon.SelectedImageIndex = GetImageIndex(column); nodeSon.ImageIndex = GetImageIndex(column); node.Nodes.Add(nodeSon); } } groupBox1.Controls.Add(tree); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 根据父节点表获取选择的字段 /// </summary> /// <param name="n"></param> /// <returns></returns> public static TreeView TreeChind(TreeNode n) { TreeView tree = new TreeView(); AdvancedTreeNode node; string ParentName = ((Model.TreeNodeTag)n.Parent.Tag).Tag.ToString(); if (n.Nodes.Count > 0) { foreach (TreeNode item in n.Nodes) { if (!item.Checked) { continue; } node = new AdvancedTreeNode(); node.Text = item.Text; node.Name = item.Name; node.Value = item; node.SelectedImageIndex = (int)DBImage.TABLE; node.ImageIndex = (int)DBImage.TABLE; node.Checked = item.Checked; tree.Nodes.Add(node); } } else { var fields = Database.GetFields(StaticTool.ServerID, ParentName, n.Name); foreach (var field in fields) { node = new AdvancedTreeNode(); node.Name = field.Name; node.Text = string.Format("{0}({1}{2},{3})", field.Name, field.Type, field.Length != -1 ? "(" + field.Length.ToString() + ")" : "", field.IsNull ? "null" : "not null"); node.ImageIndex = field.IsPrimaryKey ? 5 : 3; node.SelectedImageIndex = field.IsPrimaryKey ? 5 : 3; node.Tag = new Model.TreeNodeTag() { Type = TreeNodeType.Field, Tag = field }; node.Checked = true; tree.Nodes.Add(node); } } return(tree); }
private void AddOrRemoveSelectedQuestion(AdvancedTreeNode node, bool value) { IQuestionClass item = _questions.FirstOrDefault(i => i.Title == node.Text); if (item != null) { if (value) { if (!_selectedQuestions.Contains(item)) { _selectedQuestions.Add(item); } } else { _selectedQuestions.Remove(item); } } }
public TreeView InitTreeView(string seach) { TableBusiness tableBusiness = new TableBusiness(); TreeView tree = new TreeView(); tree.Name = "tvTables"; tree.CheckBoxes = true; try { AdvancedTreeNode node; AdvancedTreeNode nodeSon; List <Table> lstTable = tableBusiness.ListTables(ConnBuilder, seach); foreach (Table table in lstTable) { node = new AdvancedTreeNode(); node.Checked = true; node.Text = table.Name; node.Value = table; node.SelectedImageIndex = (int)DBImage.TABLE; node.ImageIndex = (int)DBImage.TABLE; tree.Nodes.Add(node); foreach (Column column in table.Columns) { nodeSon = new AdvancedTreeNode(); nodeSon.Checked = true; nodeSon.Text = column.Name + " (" + ListarAtributos(column) + ")"; nodeSon.Value = column; nodeSon.SelectedImageIndex = GetImageIndex(column); nodeSon.ImageIndex = GetImageIndex(column); node.Nodes.Add(nodeSon); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(tree); }