示例#1
0
        //Add SERVER or group from user input
        private void button2_Click(object sender, EventArgs e)
        {
            //grab selected node
            TreeNode treeNode = treeView1.SelectedNode;

            //If no node is selected select ROOT
            if (treeNode == null)
            {
                treeNode = treeView1.Nodes[0];
            }

            string inputBox = Interaction.InputBox("Please enter server/group name:");

            try
            {
                if (inputBox.Length > 0)
                {
                    if (ValidateString.IsValid(inputBox) == true)
                    {
                        treeNode.Nodes.Add(inputBox.Replace(" ", String.Empty));
                        treeNode.ExpandAll();
                        MessageBox.Show("Entries added!");
                    }
                    else
                    {
                        MessageBox.Show("Servers or groups cannot contain any special characters or start with numbers!");
                    }
                }
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
示例#2
0
        //add servers from textbox to treeview
        private void addServers_Click(object sender, EventArgs e)
        {
            try
            {
                bool returnValue = true;
                //find selected node
                foreach (TreeNode tn in treeView1.Nodes)
                {
                    RecursiveSearch(tn.Nodes);
                }

                //set selected node for nodes to be added under
                TreeNode tn2 = new TreeNode();
                tn2 = treeView1.SelectedNode;

                //split textbox
                var textLines = textBox1.Text.Split('\n');

                //loop through lines to add
                foreach (var ln in textLines)
                {
                    if (ln != "")
                    {
                        if (ValidateString.IsValid(ln) == true)
                        {
                            tn2.Nodes.Add(ln.Replace(" ", String.Empty).ToString());
                        }
                        else
                        {
                            MessageBox.Show("Entries cannot contain any special characters or begin with numbers!");
                            returnValue = false;
                        }
                    }
                }

                if (returnValue != false)
                {
                    treeView1.ExpandAll();
                    MessageBox.Show("Entries added!");
                    textBox1.Clear();
                }
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }