Hallo zusammen,
ich versuche eine Funktion zu erweitern und komme nicht weiter.
Ich habe eine Suchfunktion und die Ergebnisse werden in der Listbox aufgelistet.
Alle Dateien (Office und pdf) haben Zusatzinformationen unter Dateieigenschaften (Autor, Comments, Tags) und das möchte ich auch in Listbox auflisten.
Wie kann ich es am besten realisieren?
Gruß
Alex
ich versuche eine Funktion zu erweitern und komme nicht weiter.
Ich habe eine Suchfunktion und die Ergebnisse werden in der Listbox aufgelistet.
Alle Dateien (Office und pdf) haben Zusatzinformationen unter Dateieigenschaften (Autor, Comments, Tags) und das möchte ich auch in Listbox auflisten.
Wie kann ich es am besten realisieren?
Gruß
Alex
Quellcode
- Imports System.IO
- Public Class Form1
- Private paths() As String = {"x"}
- Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
- On Error Resume Next
- Process.Start(paths(ListBox1.SelectedIndices(0) + 1))
- End Sub
- Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
- 'On Error GoTo ErrorHandler
- On Error Resume Next
- If e.Index < 0 Then Exit Sub
- ' Text, der angezeigt werden soll
- Dim sData As String = ListBox1.Items(e.Index).ToString
- ' Schriftart
- Dim oFont As Font = ListBox1.Font
- ' Hintergrund zeichnen
- e.DrawBackground()
- With e.Graphics
- ' jede 2. Zeile einfärben
- ' aber nur, wenn die Zeile nicht selektiert ist
- If (e.State And DrawItemState.Selected) = 0 AndAlso e.Index Mod 2 = 0 Then
- .FillRectangle(Brushes.WhiteSmoke, e.Bounds)
- End If
- ' Text ausgeben
- .DrawString(sData, oFont, New SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y)
- End With
- End Sub
- Private Sub ListBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
- On Error Resume Next
- If e.KeyCode = Keys.Enter Then ' Wenn in Combobox4 Enter gedrückt wird..
- Process.Start(paths(ListBox1.SelectedIndices(0) + 1))
- End If
- End Sub
- Private Sub FilesToListbox(ByVal lboFiles As ListBox, _
- ByVal DirectoryToSearch() As String, ByVal Searchpattern() As String)
- lboFiles.DataSource = Nothing
- Dim Filetable As New DataTable
- If FilesToDatatable(Filetable, DirectoryToSearch, Searchpattern) < 1 Then
- MsgBox("Keine Dateien gefunden")
- Exit Sub
- End If
- Dim bsFiles As New BindingSource
- bsFiles.DataSource = Filetable
- lboFiles.DisplayMember = "FileName"
- lboFiles.DataSource = bsFiles
- bsFiles.Sort = "FileName ASC" 'Sortierspalte(n) und Richtung angeben
- 'bsFiles.Filter Filterkriterium angeben
- End Sub
- Private Function FilesToDatatable(ByVal FileTable As DataTable, _
- ByVal DirectoryToSearch() As String, _
- ByVal Searchpattern() As String) As Integer
- ProgressBar1.Value = 0
- If FileTable Is Nothing Then FileTable = New DataTable
- If Not FileTable.Columns.Contains("FileName") Then
- FileTable.Columns.Add(New DataColumn("FileName", GetType(String)))
- End If
- If Not FileTable.Columns.Contains("FilePath") Then
- FileTable.Columns.Add(New DataColumn("FilePath", GetType(String)))
- End If
- FileTable.Rows.Clear()
- Try
- For Each direc As String In DirectoryToSearch
- If IO.Directory.Exists(direc) Then
- For Each sp As String In Searchpattern
- For Each file As String In IO.Directory.GetFiles(direc, _
- sp)
- FileTable.Rows.Add(IO.Path.GetFileName(file), direc)
- Next file
- Next sp
- End If
- Next direc
- Return FileTable.Rows.Count
- Catch ex As Exception
- Return -1
- End Try
- End Function
- Private Function searchFiles(ByVal dPath As DirectoryInfo, ByVal _
- lSearchpattern As List(Of String)) As List(Of FileInfo)
- Dim lFiles As List(Of FileInfo) = New List(Of FileInfo)
- On Error Resume Next
- For Each sPattern As String In lSearchpattern
- For Each fiFile As FileInfo In dPath.GetFiles(sPattern, SearchOption.AllDirectories)
- lFiles.Add(fiFile)
- Next
- Next
- Return lFiles
- End Function
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim dInitPath As DirectoryInfo
- Dim lSearchpattern As List(Of String)
- Dim lFiles As List(Of FileInfo)
- ProgressBar1.Value = 0
- ProgressBar1.Style = ProgressBarStyle.Continuous
- ListBox1.Items.Clear()
- ReDim paths(0)
- lSearchpattern = New List(Of String)
- lSearchpattern.Add("*" & ComboBox2.Text & "*" & "*" & TextBox1.Text & "*" & "*" & ComboBox1.Text & "*" & "*" & TextBox2.Text & "*" & "*." & "*")
- dInitPath = New IO.DirectoryInfo(".\Datenbank\Produkte")
- lFiles = searchFiles(dInitPath, lSearchpattern)
- For Each fiFile As FileInfo In lFiles
- ListBox1.Items.Add(fiFile.Name)
- ReDim Preserve paths(paths.Length)
- paths(paths.Length - 1) = fiFile.FullName
- ProgressBar1.Increment(1)
- If ProgressBar1.Value = 100 Then
- End If
- ProgressBar1.Maximum = lFiles.Count
- Next
- End Sub