private void PopulateTreeView(int parentNodeVal, DataTable dt) { foreach (DataRow r in dt.Rows) { TreeNode t1 = new TreeNode(); TreeNode pIndex = Node(r["PARENT"].ToString()); t1.NodeKey = r["UID"].ToString(); t1.Text = r["NODE"].ToString(); OnNextSnippet(this, new NextSnippetEventArgs(t1.NodeKey)); if (parentNodeVal != -1) { // child node if (pIndex != null) { AddNode(t1, pIndex.Key?.ToString()); } } else { // It's a root node AddNodeRoot(t1); } if (ContainsNode(r["UID"].ToString())) { PopulateTreeView(Int32.Parse(r["UID"].ToString()), SnippetDb.PopulateTreeQuery(Int32.Parse(r["UID"].ToString()))); } } }
public void PopulateTreeView(int parentNodeVal) { if (parentNodeVal == -1 || ContainsNode(parentNodeVal.ToString())) { using (DataTable y = SnippetDb.PopulateTreeQuery(parentNodeVal)) { OnSendTotal(this, new TotalCountEventArgs(y.Rows.Count)); PopulateTreeView(parentNodeVal, y); OnComplete(this, new EventArgs()); } } }
protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) { base.OnAfterLabelEdit(e); bool invalidText = false; if (e.Label != null) { if (e.Label.Length > 0) { var h = e.Label; if (e.Label.IndexOfAny(new char[] { '@', '.', ',', '!' }) > -1) { invalidText = true; Regex r = new Regex(@"[@\.\,!]"); h = r.Replace(e.Label, "_"); r = null; } if (e.Node.Text == String.Empty) { // Brand New Node, Doesn't Exist Yet. e.Node.Text = h; e.Node.EndEdit(false); // Store in Database SnippetDb.InsertNodeV1( (e.Node != null ? Int32.Parse(((TreeNode)e.Node).NodeKey.ToString()) : 0), (e.Node.Parent != null ? Int32.Parse(((TreeNode)e.Node.Parent).NodeKey.ToString()) : -1), e.Node.Text ); } else { e.Node.Text = h; e.Node.EndEdit(false); // Update Database SnippetDb.RenameNode(Int32.Parse(((TreeNode)e.Node).NodeKey), e.Node.Text); } if (invalidText) { MessageBox.Show("Invalid tree node label.\n" + "The invalid characters are: '@','.', ',', '!', replaced with '_'", "Node Label Edit"); return; } } LabelEdit = false; } }