There's error in removing items from the list box. please help.

SuperShinta

Member
Joined
Oct 8, 2011
Messages
12
Programming Experience
Beginner
Imports System.Collections.Generic
Imports 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
----------------------------------------------------------------------------------------------------------------------------------------
Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
Form5.Show()
End Sub
----------------------------------------------------------------------------------------------------------------------
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
lstFileList.Items.Remove(lstFileList.SelectedItem) -------> an error appears "Items collection cannot be modified when the DataSource property is set"
End Sub
End Class

Please help i'm workin on my thesis i have 1 week. ;((
 
You have to modify the datasource instead, BindingSource has a RemoveCurrent method.
 
When you bind the control, i.e. set its DataSource, then the control displays what's in the data source. If you want to remove an item then you must remove it from the data source, not the control directly.
 
When you bind the control, i.e. set its DataSource, then the control displays what's in the data source. If you want to remove an item then you must remove it from the data source, not the control directly.


I don't understand. I'm newbie, could you help me? Code for this, thanks in advance and i want to add progress bar could you help me also? I've searched it but i don't know where i gonna put it. Thanks in advance! :)
 

Latest posts

Back
Top