Sort a ListView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    Sort a ListView

    its about Sorting a list view
    but its not working.
    please help.......[code=vb]
    Private Sub ListView1_Colum nClick(ByVal ColumnHeader As MSComctlLib.Col umnHeader)
    'Determine whether the column is the same as the last column clicked.
    If e.Column <> sortColumn Then
    'Set the sort column to the new column.
    sortColumn = e.Column
    'Set the sort order to ascending by default.
    ListView1.Sorte d = SortOrder.Ascen ding
    ListView1.Sorte d
    Else
    'Determine what the last sort order was and change it.
    If ListView1.Sorte d = SortOrder.Ascen ding Then
    ListView1.Sorte d = SortOrder.Desce nding
    Else
    ListView1.Sorte d = SortOrder.Ascen ding
    End If
    End If
    'Call the sort method to manually sort.
    'listView1.Sort ()
    'Set the ListViewItemSor ter property to a new ListViewItemCom parer
    'object.
    'listView1.List ViewItemSorter = New ListViewItemCom parer(e.Column,
    'ListView1.Sort ing
    End Sub[/code]


    This is not working..please help...THANKS IN ADVANCE
    Last edited by debasisdas; Dec 11 '07, 11:30 AM. Reason: formatted using code tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    hI,

    Instead of checking for ListView1.Sorte d,
    Check For : ListView1.Order = SortOrder.Ascen ding...
    (For both Ascending/Descending..)

    Regards
    Veena

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #3
      ERROR " OBject required"

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        run in debug mode and check which line is creating the error.

        Comment

        • Vbbeginner07
          New Member
          • Dec 2007
          • 103

          #5
          If e.Column <> sortColumn Then
          'Set the sort column to the new column.
          sortColumn = e.Column

          Comment

          • VACEPROGRAMER
            Banned
            New Member
            • Nov 2007
            • 167

            #6
            To sort the listbox or texbox you will need at last 3 pages code on A4 format page. I have make program that sort textbox. Now for you i will try to make a program to sort listbox collections.

            SOON i will send to you

            Vace

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by VACEPROGRAMER
              To sort the listbox or texbox you will need at last 3 pages code on A4 format page. I have make program that sort textbox. Now for you i will try to make a program to sort listbox collections.
              A ListView is not the same as a ListBox. To sort a ListBox, you simply set the Sorted property to True.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Can someone explain to me what e represents?

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Hi Killer,

                  He is using VB.net, "e" is the Column Header of the ListView which is Clicked..

                  Regards
                  Veena

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by QVeen72
                    He is using VB.net, "e" is the Column Header of the ListView which is Clicked..
                    How is anyone supposed to know that? It doesn't appear to be declared anywhere.

                    In fact, isn't that sort of what "Object required" means? It doesn't know any object at that point called e?

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Hi Killer,

                      "e" is the argument passed in the ColumnClick event of the listview:

                      [code=vbnet]
                      Private Sub ListView1_Colum nClick(ByVal sender As Object, ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles ListView1.Colum nClick

                      End Sub
                      [/code]

                      Regards
                      Veena

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Originally posted by QVeen72
                        [code=vbnet]Private Sub ListView1_Colum nClick(ByVal sender As Object, ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles ListView1.Colum nClick[/code]
                        Well, that's certainly not what it says in post #1.

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          He must have Wrongly typed...

                          Regards
                          Veena

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by QVeen72
                            He must have Wrongly typed...
                            Seems likely, doesn't it. However, the lack of e would seem to explain the reported error ("object required").

                            Vbbeginner07, can you try modifying the Sub declaration to match post #11, and let us know what happens?

                            Comment

                            Working...