ImageList erweitern

  • .NET (FX) 4.5–4.8
  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    ImageList erweitern

    Hallo liebes Forum...

    ich habe eine Funktion, die mir ein ListView wie folgt füllt:



    Ich möchte die Funktion gern so erweitern, dass die Dateien nach Erstelldatum aufsteigend, also die älteste Datei als letztes, sortiert werden.

    Hat jemand eine Idee, wie das möglich ist? Oder gibt es dafür mittlerweile was fertiges?

    Hier der Code:


    VB.NET-Quellcode

    1. Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    2. Dim parts() As String = Split(My.User.Name, "\")
    3. Dim username As String = parts(1)
    4. lblUser.Text = "Angemeldet als " & username
    5. ListView1.LargeImageList = ImageList1
    6. ListView1.SmallImageList = ImageList1
    7. ListView1.View = System.Windows.Forms.View.List
    8. Dim SuchPfad As String
    9. Dim dirInfo As DirectoryInfo
    10. Dim fileInfo As FileInfo
    11. Dim exeIcon As System.Drawing.Icon
    12. SuchPfad = "C:\Test\Daten"
    13. dirInfo = New DirectoryInfo(SuchPfad)
    14. LabelOrdner.Text = SuchPfad
    15. For Each fileInfo In dirInfo.GetFiles
    16. If (Not String.IsNullOrEmpty(fileInfo.Extension)) Then
    17. exeIcon = System.Drawing.Icon.ExtractAssociatedIcon(fileInfo.FullName)
    18. If (ImageList1.Images.ContainsKey(fileInfo.FullName)) Then
    19. ListView1.Items.Add(fileInfo.Name, fileInfo.FullName)
    20. ElseIf (Not exeIcon Is Nothing) Then
    21. ImageList1.Images.Add(fileInfo.FullName, exeIcon)
    22. With ListView1.Items.Add(fileInfo.Name, fileInfo.FullName)
    23. End With
    24. Else
    25. ListView1.Items.Add(fileInfo.Name)
    26. End If
    27. End If
    28. Next
    29. End Sub
    30. Public Function GetAssociatedProgram(ByVal FileExtension As _
    31. String) As String
    32. ' Returns the application associated with the specified
    33. ' FileExtension
    34. ' ie, path\denenv.exe for "VB" files
    35. Dim objExtReg As Microsoft.Win32.RegistryKey = _
    36. Microsoft.Win32.Registry.ClassesRoot
    37. Dim objAppReg As Microsoft.Win32.RegistryKey = _
    38. Microsoft.Win32.Registry.ClassesRoot
    39. Dim strExtValue As String
    40. Try
    41. ' Add trailing period if doesn't exist
    42. If FileExtension.Substring(0, 1) <> "." Then _
    43. FileExtension = "." & FileExtension
    44. ' Open registry areas containing launching app details
    45. objExtReg = objExtReg.OpenSubKey(FileExtension.Trim)
    46. strExtValue = objExtReg.GetValue("").ToString
    47. objAppReg = objAppReg.OpenSubKey(strExtValue & _
    48. "\shell\open\command")
    49. ' Parse out, tidy up and return result
    50. Dim SplitArray() As String
    51. SplitArray = Split(objAppReg.GetValue(Nothing).ToString, """")
    52. If SplitArray(0).Trim.Length > 0 Then
    53. Return SplitArray(0).Replace("%1", "")
    54. Else
    55. Return SplitArray(1).Replace("%1", "")
    56. End If
    57. Catch
    58. Return ""
    59. End Try
    60. End Function



    Vielen Dank schon mal...

    Fragen ins Forum; Tipps & Tutorials in "Tipps & Tutorials". Ganz einfach, wirklich! Verschoben. ~fufu
    Bilder
    • menu.JPG

      23,85 kB, 571×422, 155 mal angesehen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „fufu“ ()