When removing items the next items doesn't remove only the first one. please help

SuperShinta

Member
Joined
Oct 8, 2011
Messages
12
Programming Experience
Beginner
Code:
Imports System.Collections.GenericI
mports System.Net
Imports System.IO


Public Class Form2
    'Dim filename As String
    Public ftpSettings As FtpClient


    Private Sub cmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpload.Click


        host = "ftp://" & txturl.Text
        username = txtusername.Text
        password = txtpassword.Text


        Dim ftpSettings As New FtpClient
        ftpSettings.Host = txturl.Text
        ftpSettings.UserName = txtusername.Text
        ftpSettings.Password = txtpassword.Text


        modMain.FTPClientInstance = New FtpClient
        modMain.FTPClientInstance = ftpSettings


        Dim uploadedFileCount As Integer = 0


        'Loop through all the files that will be uploaded in the list box
        For Each item As KeyValuePair(Of String, String) In lstFileList.Items
            'Get the files information using the FileInfo class provided by .Net
            Dim fileInfo As New FileInfo(item.Value)


            Dim result As Boolean = False


            'Call the upload function
            uploadedFileCount += 1
            result = modMain.FTPClientInstance.FtpFileUpload(fileInfo)
            If (result) Then
            End If
        Next


        MsgBox(String.Format("You have successfully uploaded {0} File/s!", uploadedFileCount))


    End Sub


    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        username = txtusername.Text
    End Sub


    Private Sub txtpassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        password = txtpassword.Text
    End Sub


    Private Sub lstFileList_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles lstFileList.DragEnter
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            e.Effect = DragDropEffects.All
        Else
            e.Effect = DragDropEffects.None
        End If


    End Sub


    Private Sub lstFileList_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles lstFileList.DragDrop
        Dim s() As String = e.Data.GetData("FileDrop", False)
        Dim i As Integer
        For i = 0 To s.Length - 1


            Dim filePath As String = s(i)
            Dim fileInfo As New FileInfo(filePath)


            modMain.FileList.Add(fileInfo.Name, fileInfo.FullName)


        Next i


        BindFileList()


    End Sub


    Private Sub BindFileList()
        Dim bindSource As New BindingSource(modMain.FileList, Nothing)


        lstFileList.DataSource = bindSource
        lstFileList.DisplayMember = "Key"
        lstFileList.ValueMember = "Value"




    End Sub


    Public Sub RemoveCurrent()
        Dim removefile As New BindingSource(modMain.FileList, Nothing)


        removefile.RemoveCurrent()
        lstFileList.DataSource = removefile
        lstFileList.DisplayMember = "Key"
        lstFileList.ValueMember = "Value"


    End Sub


    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click


        RemoveCurrent()


    End Sub
End Class
I don't know what's wrong, i can only move the 1st item but the second and so on doesn't make any changes. It remains in a listbox. Please help. Thank you in advance :)
 

Estuardo

Well-known member
Joined
Nov 27, 2004
Messages
45
Location
Portugal
Programming Experience
5-10
G'd morning!
i guess you should start to check if you're really looping (i gues you don't). Then check this line

For Each item As KeyValuePair(Of String, String) In lstFileList.Items

I can't see how you can run that part of code without error. to loop through ListViewItem[/COLOR="#000080"] type with strings
The code should look like this
Code:
for each itm as ListViewItem in lstFileList.items

    Dim fileInfo As New FileInfo(itm.text)
      .
      . 
      .
next
Note that in your case you have the full file path as subitem, so the line above should be itm.SubItems(1).Text.

G'd Luck
 
Top Bottom