我有两个checklistbox。一个是我要复制的文件夹列表。第二个是我要将文件夹复制到的位置列表。
问题是我不知道如何点击清单箱并移动到该位置。我所做的就是设置一个修复位置,我可以从文件夹test复制到文件夹。但是我想在清单中选择勾选并从方框1移动到方框2,而不是固定位置和文件夹。
Private Sub moveContainerToLocation_Click(sender As System.Object, e As System.EventArgs) Handles moveContainerToLocation.Click
'To do
Try
Dim fileToCopy As String
Dim NewCopy As String
Dim fileSize As Long
' fileToCopy is folder i want to move
' NewCopy is the location what we choose to move the folder to
fileToCopy = "C:\folder test"
NewCopy = "C:\folder"
fileSize = GetFolderSize(fileToCopy)
' allow to overwrite
My.Computer.FileSystem.CopyDirectory(fileToCopy, NewCopy, True)
Timer1.Start()
moveContainerToLocation.Enabled = False
' the percentage of files transferred and use it into the progressbar
Dim counter =Directory.GetFiles(fileToCopy,"*",SearchOption.AllDirectories).Length
'Next
Catch ex As Exception
MessageBox.Show("ERROR")
End Try
End Sub
''这是将我的文件夹放入checklistbox1
Private Sub GetfolderButton_Click(sender As System.Object, e As System.EventArgs) Handles GetContainerButton.Click
For Each dra As String In Directory.GetDirectories("C:\folder test")
Container.Items.Add(dra)
Next
End Sub
''这是我的位置在我的checklistbox1
Private Sub getLocationButton_Click(sender As System.Object, e As System.EventArgs) Handles getLocationButton.Click
For Each dr As String In Directory.GetDirectories("C:\folder")
Location.Items.Add(dr)
Next
End Sub
答案 0 :(得分:0)
如果我正确理解了您的问题,那么您正在询问如何在CheckedListBox
中获取已检查的项目,对吧?第一件事是,CheckedListBox中可能存在多个已检查的项目。所以你不会得到一个答案。
If CheckedListBox1.CheckedItems.Count = 0 Then
MsgBox("Please select something")
Return
ElseIf CheckedListBox1.CheckedItems.Count > 1 Then
MsgBox("Please select only one item")
Return
End If
NewCopy = CheckedListBox1.CheckedItems(0)