Guten Tag, ich kann ich am besten die selektierten Dateien im ListView Löschen? Mit Löschen meine ich, vom PC Löschen.
Mfg
Mfg
VB.NET-Quellcode
- Public Class Form1
- Private _LastSelectedFolder As String = String.Empty
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Using dlg As New FolderBrowserDialog
- With dlg
- .Description = "Verzeichnis auswählen..."
- .ShowNewFolderButton = False
- .SelectedPath = _LastSelectedFolder
- .RootFolder = Environment.SpecialFolder.MyComputer
- If .ShowDialog = Windows.Forms.DialogResult.OK Then
- Try
- _LastSelectedFolder = .SelectedPath
- Me.ShowFileList(.SelectedPath & "\oxide\data", ListView1, ImageList1)
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End If
- End With
- End Using
- End Sub
- Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
- With DirectCast(sender, ListView)
- If .FocusedItem IsNot Nothing Then
- Dim locFi As IO.FileInfo = CType(.FocusedItem.Tag, IO.FileInfo)
- Process.Start(locFi.FullName)
- locFi = Nothing
- End If
- End With
- End Sub
- Private Sub ListView1_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
- If e.IsSelected Then
- ToolStripStatusLabel1.Text = DirectCast(e.Item.Tag, IO.FileInfo).FullName
- Else
- ToolStripStatusLabel1.Text = String.Empty
- End If
- End Sub
- Private Sub ShowFileList(ByVal folder As String, ByVal ltv As ListView, ByVal imgList As ImageList)
- If String.IsNullOrEmpty(folder) Then Throw New ArgumentNullException("Path")
- Dim locDirInfo As IO.DirectoryInfo = Nothing
- Dim locLtvItem As ListViewItem = Nothing
- With ltv
- Try
- .BeginUpdate()
- .Items.Clear()
- .Columns.Clear()
- .Columns.Add("Dateiname", 100, HorizontalAlignment.Left)
- .Columns.Add("Größe (Bytes)", 100, HorizontalAlignment.Right)
- .Columns.Add("Typ", 100, HorizontalAlignment.Left)
- .Columns.Add("Letzte Änderung", 120, HorizontalAlignment.Left)
- .GridLines = True
- .FullRowSelect = True
- .MultiSelect = True
- .View = View.Details
- .CheckBoxes = True
- imgList.Images.Clear()
- .SmallImageList = imgList
- locDirInfo = New IO.DirectoryInfo(folder)
- If Not locDirInfo.Exists Then Throw New IO.DirectoryNotFoundException
- For Each locFi As IO.FileInfo In locDirInfo.GetFiles("*.*", IO.SearchOption.AllDirectories)
- If Not imgList.Images.ContainsKey(locFi.Extension) Then
- imgList.Images.Add(locFi.Extension, Icon.ExtractAssociatedIcon(locFi.FullName))
- End If
- locLtvItem = New ListViewItem(New String() {locFi.Name,
- locFi.Length.ToString("n"),
- locFi.Extension,
- locFi.LastAccessTime.ToString})
- locLtvItem.Tag = locFi
- locLtvItem.ImageKey = locFi.Extension
- .Items.Add(locLtvItem)
- Next
- Catch ex As Exception
- Throw ex
- Finally
- .EndUpdate()
- locDirInfo = Nothing
- locLtvItem = Nothing
- End Try
- End With
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Try
- Dim I As Integer
- If ListView1.CheckedItems.Count = 0 Then
- For I = 0 To ListView1.Items.Count - 1
- Next
- Else
- For I = 0 To ListView1.CheckedItems.Count - 1
- Next
- End If
- Catch ex As Exception
- MessageBox.Show(ex.Message)
- End Try
- End Sub
- End Class