Example #1
0
        private void DeleteNode(AIONode [] nodesToDelete)
        {
            for (int i = 0; i < nodesToDelete.Length; i++)
            {
                AIONode nodeToDelete = nodesToDelete[i];

                try
                {
                    tree.DeleteNode(nodeToDelete);

                    if (nodeToDelete.data.isFile == false)
                    {
                        TreeNode toDelete = (TreeNode)nodeToDelete.container;
                        if (toDelete != null)
                        {
                            toDelete.Remove();
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
            UpdateListView();
        }
        private void listView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)             //Delete
            {
                if (listView1.SelectedIndices.Count == 0)
                {
                    return;
                }

                int     index        = listView1.SelectedIndices[0];
                AIONode nodeToDelete = (AIONode)listView1.Items[index].Tag;

                //Delete
                tree.DeleteNode(nodeToDelete);

                //Update tree if isFolder
                if (nodeToDelete.data.isFile == false)
                {                /*
                                  *     TreeNode selected = treeView1.SelectedNode;
                                  *     int i = 0;
                                  *     for (i = 0;i<selected.Nodes.Count;i++)
                                  *     {
                                  *             if (selected.Nodes[i].Text.Equals(nodeToDelete.info.Name))
                                  *                     break;
                                  *     }
                                  *     //Delete node at tree
                                  *     selected.Nodes.RemoveAt(i);*/
                    TreeNode node = (TreeNode)nodeToDelete.container;
                    node.Remove();
                }
                //Refresh
                UpdateListView();
            }
        }