Beispiel #1
0
        private void addNodeToolStripMenuItem_Click(object sender,
                                                    EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;

            if (tn != null)
            {
                DataRows.MyRow r   = tn.Tag as DataRows.MyRow;
                AddNameForm    frm = new AddNameForm();
                if (r != null)
                {
                    frm.r = r;
                }
                frm.tn = tn;
                frm.ShowDialog();
            }
        }
Beispiel #2
0
 private void FillTreeView(string currKeyRoot, TreeNode tn)
 {
     DataRows.MyRow row = drows.GetNextRow();
     while (row != null)
     {
         if (NodeStartsWith(row.TreeKey, currKeyRoot))
         {
             TreeNode tnChild = new TreeNode(row.Data + "["
                                             + row.TreeKey + "]");
             tnChild.Tag = row;
             tn.Nodes.Add(tnChild);
             FillTreeView(row.TreeKey, tnChild);
         }
         else
         {
             drows.MovePrev();
             return;
         }
         row = drows.GetNextRow();
     }
 }
Beispiel #3
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode tn = e.Data.GetData("System.Windows.Forms.TreeNode")
                          as TreeNode;
            TreeViewHitTestInfo hi = treeView1.HitTest(
                treeView1.PointToClient(new Point(e.X, e.Y)));

            if (hi.Node != null && tn != null)
            {
                DataRows.MyRow rSrc  = tn.Tag as DataRows.MyRow;
                DataRows.MyRow rDest = hi.Node.Tag as DataRows.MyRow;
                SqlConnection  conn  = new SqlConnection(
                    @"Data Source=192.168.2.110;Initial Catalog=treeview;User Id=sa;Password=sa;");
                conn.Open();
                int    dashpos = rSrc.TreeKey.LastIndexOf('.');
                string subSrc  = (dashpos > 0 ? rSrc.TreeKey.Substring(0,
                                                                       dashpos) : "");
                SqlCommand cmd = new SqlCommand(
                    "update datatable set treekey = '" + rDest.TreeKey
                    + "' + right(treekey, len(treekey) - len('"
                    + subSrc + "')) where left(treekey, len('"
                    + rSrc.TreeKey + "')) + '.' = '"
                    + rSrc.TreeKey + "." + "'", conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                drows = new DataRows();
                treeView1.Nodes.Clear();
                TreeNode tnRoot = new TreeNode("Root");
                treeView1.Nodes.Add(tnRoot);
                FillTreeView("", tnRoot);
                SortNodes(null);
            }
            else
            {
                MessageBox.Show("Not found");
            }
        }
Beispiel #4
0
        private void deleteNodeToolStripMenuItem_Click(object sender,
                                                       EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;

            if (tn != null)
            {
                DataRows.MyRow r = tn.Tag as DataRows.MyRow;
                if (r != null)
                {
                    SqlConnection conn = new SqlConnection(
                        @"Data Source=192.168.2.110;Initial Catalog=treeview;User Id=sa;Password=sa;");
                    conn.Open();
                    if (MessageBox.Show(
                            "Do you want to delete all child nodes?",
                            "Delete Node", MessageBoxButtons.YesNo)
                        == DialogResult.Yes)
                    {
                        SqlCommand cmd = new SqlCommand(
                            "delete datatable where treekey = '" + r.TreeKey
                            + "' or treekey like '" + r.TreeKey + ".%'",
                            conn);
                        cmd.ExecuteNonQuery();
                        tn.Parent.Nodes.Remove(tn);
                    }
                    else
                    {
                        SqlCommand cmd = new SqlCommand(
                            "delete datatable where treekey = '" +
                            r.TreeKey + "'", conn);
                        cmd.ExecuteNonQuery();
                        tn.Parent.Nodes.Remove(tn);
                    }
                    conn.Close();
                }
            }
        }