Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code below where we get the code for the selected listview item and delete it from a specific location and then display a message that it was deleted. The issue i have with it is that i want to select multiple items and delete them. can someone help show me how i would do that with the code and then display all the names that were deleted in a textbox.

now there are 2 items that get deleted one is from a file and the other item is a folder on a remote machine. I have the dashed lines separating the 2 and the thrid is just displaying what was deleted in a diaplogbox that pops up.

I m new to programming and i have been trying to use a loop but i seem to just get one item. Any help would be great.

VB
Private Sub DeleteHeapAndFolderToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteHeapAndFolderToolStripMenuItem.Click
    If strComputer = "" Then
        strComputer = "127.0.0.1"
    End If

    Dim heap_num = Radia_Listview.SelectedItems(0).Text 'heap number
    Dim Process = GetObject("winmgmts://./root/novadigm:NVD_Agent")
    Dim method = Process.Methods_("DeleteInstance")
    Dim inParameters = method.inParameters.SpawnInstance_()
    inParameters.Path = "c:\temp\aservice.edm"
    inParameters.Index = heap_num
    Dim outParameters = Process.ExecMethod_("DeleteInstance", inParameters)
    '---------------------------------------------
    Dim Zdelete = Radia_Listview.SelectedItems(0).SubItems(1).Text ' heap name.
    Dim ZPATH As String = "\\" & strComputer & "\C$\Progra~1\Novadigm\Lib\SYSTEM\RADDBT3\SOFTWARE\ZSERVICE\"
    If System.IO.Directory.Exists(ZPATH & Zdelete) Then
        Directory.Delete(ZPATH & Zdelete, True)
    End If
    Dim copyFrom As String = "C:\temp\ASERVICE.EDM"
    Dim copyTo As String = "\\" & strComputer & "\C$\Progra~1\Novadigm\Lib\SYSTEM\RADDBT3\SOFTWARE\ASERVICE.EDM"
    File.Copy(copyFrom, copyTo, True)
    '----------------------------------------------
    Del_Heap.Del_TextBox.Text = Zdelete
    Del_Heap.Show()
        Radia_Listview.Items.Clear()
    Application.Radia_Query_Aservice_Button.PerformClick()
End Sub
Posted

I fixed this myself:


VB
'=======================================================================================
'The below code will create an array for the items that need to be deleted from Zservice
'=======================================================================================

' Delcaring the selected items as heap_num
Dim Zheap_num = CAE_Listview.SelectedItems(0).SubItems(1).Text ' heap name
Dim ZPATH As String = "\\" & strComputer & "\C$\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ZSERVICE\"
Dim Zlist As New ArrayList

'For each selected item add the item number to an array list
For Each sITEM In Zheap_num
    Zlist.Add(sITEM)
Next

'reverse the arraylist from 012345 to 543210
Zlist.Reverse()


For Each DelZ In Zlist
    'adds the heap name to the textbox for del_heap that will display once its finished
    'deleting the items selected
    Del_Heap.Del_TextBox.Text += DelZ.text & vbCrLf

    'if the folder exist it will delete it if it dosent exist it will keep going
    If System.IO.Directory.Exists(ZPATH & DelZ.text) Then
        Directory.Delete(ZPATH & DelZ.text, True)
    End If

Next
 
Share this answer
 
You can set the MultiSelect property of ListView to true and then use the SelectedItems property of ListView to iterate through all the selected items and perform the required action. An example is given here
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selecteditems.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900