1
我想寫一個代碼,用戶可以在其中添加文件到列表視圖。這些文件必須被移到用戶指定的位置。我無法工作的是添加到列表視圖的文件的文件路徑。下面是用於移動文件的代碼:將文件從列表視圖移動到vb.net中的新目錄
sPath = My.Settings.DefaultPath & ComboBox1.Text & "\" & ComboBox2.Text & "\"
If txtOnderwerp.Text = "" Then
If ComboBox3.Text = "Make your choice..." Then
MsgBox("Select subject!", MsgBoxStyle.Information)
Else
Try
For Each item As ListViewItem In ListView1.Items
My.Computer.FileSystem.CopyFile(item, sPath & ComboBox3.Text & "\" & item.Text, FileIO.UIOption.AllDialogs)
MsgBox("Copy succesfull.", MsgBoxStyle.Information)
ListView1.Items.Clear()
Me.Close()
Next
Catch ex As Exception
MessageBox.Show("Error copying file: " & ex.Message)
End Try
End If
End If
因爲「項目」是不是爲FilsSystem.Copy命令字符串上面的代碼狀態的錯誤。用戶可以使用此代碼將文件添加到列表視圖中:
Using ofd As New OpenFileDialog
ofd.Multiselect = True
If ofd.ShowDialog = DialogResult.OK Then
For Each fn As String In ofd.FileNames
Dim fi As New IO.FileInfo(fn)
Dim icons As Icon = SystemIcons.WinLogo
Dim li As New ListViewItem(fi.Name, 1)
If Not (ImageList1.Images.ContainsKey(fi.Extension)) Then
icons = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(fi.Extension, icons)
End If
icons = Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(icons)
ListView1.Items.Add(fi.Name, fi.Extension)
Next
End If
End Using
當您添加ListViewItem的,把音響.FullPath放入listitem的標籤。在複製時稍後使用它。 –