Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Cannot Sort Listview

Îåêßíçóå áðü ôï ìÝëïò PhillipMorris. Τελευταία δημοσίευση από το μέλος PhillipMorris στις 21-09-2006, 07:49. Υπάρχουν 0 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  21-09-2006, 07:49 17002

    Cannot Sort Listview

    Προσπαθώντας να βρω μια λύση στο Sorting του Listview βρήκα στο MSDN αυτό :

    http://msdn2.microsoft.com/en-us/library/ms229643.aspx

    το οποίο και εφάρμοσα.

    Μόλις λοιπόν ξεκινά το project και κάνω κλικ στην στήλη του Listview παράγεται το : InvalidCastException was unhandled στην πρώτη γραμμή.

    Παραθέτω και το κώδικα του listview_ColumnClick

    Private Sub listView1_ColumnClick(ByVal sender As Object, ByVal e As ColumnClickEventArgs)

        ' Create an instance of the ColHeader class.
        Dim clickedCol As ColHeader = CType(Me.listView1.Columns(e.Column), ColHeader)

        ' Set the ascending property to sort in the opposite order.
        clickedCol.ascending = Not clickedCol.ascending

        ' Get the number of items in the list.
        Dim numItems As Integer = Me.listView1.Items.Count

        ' Turn off display while data is repoplulated.
        Me.listView1.BeginUpdate()

        ' Populate an ArrayList with a SortWrapper of each list item.
        Dim SortArray As New ArrayList
        Dim i As Integer
        For i = 0 To numItems - 1
            SortArray.Add(New SortWrapper(Me.listView1.Items(i), e.Column))
        Next i

        ' Sort the elements in the ArrayList using a new instance of the SortComparer
        ' class. The parameters are the starting index, the length of the range to sort,
        ' and the IComparer implementation to use for comparing elements. Note that
        ' the IComparer implementation (SortComparer) requires the sort 
        ' direction for its constructor; true if ascending, othwise false.
        SortArray.Sort(0, SortArray.Count, New SortWrapper.SortComparer(clickedCol.ascending))

        ' Clear the list, and repopulate with the sorted items.
        Me.listView1.Items.Clear()
        Dim z As Integer
        For z = 0 To numItems - 1
            Me.listView1.Items.Add(CType(SortArray(z), SortWrapper).sortItem)
        Next z
        ' Turn display back on.
        Me.listView1.EndUpdate()
    End Sub

    Μήπως μπορεί να με βοηθήσει κανείς ; Υπάρχει ευκολότερος τρόπος για το sorting ενός Listview ; Όσα παραδείγματα βρήκα αφορούσας desktop εφαρμογές και δεν δούλευαν σε mobile.

    Ευχαριστώ

Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems