Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

List View Zahlen + Datum Sortieren

Empfohlene Antworten

Veröffentlicht

hi leute, ich hoff ihr könnt mir weiterhelfen.

Ich muss auf der arbeit nen explorer ( wie windoof explorer ) proggen. (vb.net)

ich habe schon ne GUI usw.. links in nem ListView ( lvFolder) sind die Ordner und rechts die Datein ( lvFiles) in dem View lvFiles sind 2 SubItems.

In Tabellen ( 3Spalten)

Name, Dateigröße, Erstellungsdatum.

Nun soll nach der Spalte sortiert werden auf die geklickt wird. Die sortierung nach name funktioniert bereits, und mir ist auch klar wie ich rauslese auf welche spalte geklickt wurde.

Mein prob ist nun da listview eigentlich für txt geeignet ist ordnet der mit bei sortierung nach größe oder datum die items falsch an.

Form: frmForm1

listview: lvFiles

kann mir einer weiterhelfen oder nen code geben?

thx im voraus !

( hab unter suchen und google nix brauchbares gefunden )

vielleicht besteht die möglichkeit was mit den tags von den subitems zumachen?

Hi Majestix,

schau dir das mal an.

hi, danke für die antwort, aber irgendwie hilft mir das nicht sehr viel weiter. vorallem kann ich die datein zum dl nach dem entpacken nicht öffnen...


#Region " Sortieren nach angeklickter Spalte"


    Public Class ColumnComparer

        Implements IComparer

        Private ColumnIndex As System.Int32

        Private Sorting As System.Windows.Forms.SortOrder


        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare

            Dim ix As System.Windows.Forms.ListViewItem

            Dim iy As System.Windows.Forms.ListViewItem


            ix = DirectCast(x, System.Windows.Forms.ListViewItem)

            iy = DirectCast(y, System.Windows.Forms.ListViewItem)

            If Sorting = SortOrder.Descending Then

                Return System.String.Compare(iy.SubItems(ColumnIndex).Text, ix.SubItems(ColumnIndex).Text)

            Else

                Return System.String.Compare(ix.SubItems(ColumnIndex).Text, iy.SubItems(ColumnIndex).Text)

            End If

        End Function


        Public Sub New(ByVal pColumnIndex As System.Int32, ByVal pSorting As System.Windows.Forms.SortOrder)

            ColumnIndex = pColumnIndex

            Sorting = pSorting

        End Sub

    End Class




    Private Sub lvFiles_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lvFiles.ColumnClick

        lvFiles.BeginUpdate()


        If e.Column = 0 Then

            lvFiles.ListViewItemSorter = Nothing


            If lvFiles.Sorting = SortOrder.Descending Then

                lvFiles.Sorting = SortOrder.Ascending

            Else

                lvFiles.Sorting = SortOrder.Descending

            End If


            lvFiles.Sort()

        Else

            If lvFiles.Sorting = SortOrder.Descending Then

                lvFiles.Sorting = SortOrder.Ascending

            Else

                lvFiles.Sorting = SortOrder.Descending

            End If


            lvFiles.ListViewItemSorter = New ColumnComparer(e.Column, lvFiles.Sorting)


            lvFiles.Sort()

        End If



        lvFiles.EndUpdate()

    End Sub



#End Region

Hi Majestix,

vorallem kann ich die datein zum dl nach dem entpacken nicht öffnen

hab' gerade die Source Files gezogen und entzippt.

Funktioniert alles ohne Probleme. Das Besipiel müsste genau das sein was du suchst.

hab den code jetzt selber umgeschrieben und es funktioniert.

falls jmd. interesse hat hier der code:

(trotzdem thx 4 help @ Manfred)


#Region " Sortieren nach angeklickter Spalte"


    Public Class ColumnComparer

        Implements IComparer

        Private ColumnIndex As System.Int32

        Private Sorting As System.Windows.Forms.SortOrder

        Private Typ As Integer


        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare

            Dim Result As Integer


            Dim ix As System.Windows.Forms.ListViewItem

            Dim iy As System.Windows.Forms.ListViewItem


            ix = DirectCast(x, System.Windows.Forms.ListViewItem)

            iy = DirectCast(y, System.Windows.Forms.ListViewItem)

            Select Case Typ

                Case Type_String

                    Result = System.String.Compare(ix.SubItems(ColumnIndex).Text, iy.SubItems(ColumnIndex).Text)

                Case Type_Date

                    Dim date0 As DateTime

                    Dim date1 As DateTime

                    date0 = DirectCast(ix.Tag, DateTime)

                    date1 = DirectCast(iy.Tag, DateTime)

                    Result = System.DateTime.Compare(date1, date0)

                Case Type_Integer

                    Dim int0 As Integer

                    Dim int1 As Integer


                    int0 = Integer.Parse("0" & ix.SubItems(ColumnIndex).Text)

                    int1 = Integer.Parse("0" & iy.SubItems(ColumnIndex).Text)


                    Result = int0 - int1

            End Select

            If Sorting = SortOrder.Descending Then

                Result = -Result

            End If

            Return Result

        End Function


        Public Sub New(ByVal pColumnIndex As System.Int32, ByVal pSorting As System.Windows.Forms.SortOrder, ByVal pTyp As Integer)

            ColumnIndex = pColumnIndex

            Sorting = pSorting

            Typ = pTyp

        End Sub

    End Class



    Private Const Type_Integer As Integer = 2

    Private Const Type_Date As Integer = 1

    Private Const Type_String As Integer = 0


    Private Sub lvFiles_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lvFiles.ColumnClick

        lvFiles.BeginUpdate()

        Dim typ As Integer




        If e.Column = 0 Then

            lvFiles.ListViewItemSorter = Nothing


            If lvFiles.Sorting = SortOrder.Descending Then

                lvFiles.Sorting = SortOrder.Ascending

            Else

                lvFiles.Sorting = SortOrder.Descending

            End If


            lvFiles.Sort()

        Else

            If lvFiles.Sorting = SortOrder.Descending Then

                lvFiles.Sorting = SortOrder.Ascending

            Else

                lvFiles.Sorting = SortOrder.Descending

            End If


            Select Case e.Column

                Case 0

                    typ = Type_String

                Case 1

                    typ = Type_Integer

                Case 2

                    typ = Type_Date

                Case Else

                    typ = Type_String

            End Select


            lvFiles.ListViewItemSorter = New ColumnComparer(e.Column, lvFiles.Sorting, typ)


            lvFiles.Sort()

        End If



        lvFiles.EndUpdate()

    End Sub



#End Region



Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.