By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,593 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,593 IT Pros & Developers. It's quick & easy.

Sort a ListView

100+
P: 103
its about Sorting a list view
but its not working.
please help.......
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
  2.  'Determine whether the column is the same as the last column clicked.
  3.  If e.Column <> sortColumn Then
  4.    'Set the sort column to the new column.
  5.  sortColumn = e.Column
  6.    'Set the sort order to ascending by default.
  7.  ListView1.Sorted = SortOrder.Ascending
  8. ListView1.Sorted
  9. Else
  10.   'Determine what the last sort order was and change it.
  11.   If ListView1.Sorted = SortOrder.Ascending Then
  12.       ListView1.Sorted = SortOrder.Descending
  13.    Else
  14.       ListView1.Sorted = SortOrder.Ascending
  15. End If
  16.   End If
  17.     'Call the sort method to manually sort.
  18.     'listView1.Sort()
  19.     'Set the ListViewItemSorter property to a new ListViewItemComparer
  20.     'object.
  21. 'listView1.ListViewItemSorter = New ListViewItemComparer(e.Column,
  22. 'ListView1.Sorting
  23. End Sub

This is not working..please help...THANKS IN ADVANCE
Dec 11 '07 #1
Share this Question
Share on Google+
13 Replies


QVeen72
Expert 100+
P: 1,445
hI,

Instead of checking for ListView1.Sorted,
Check For : ListView1.Order = SortOrder.Ascending...
(For both Ascending/Descending..)

Regards
Veena
Dec 11 '07 #2

100+
P: 103
ERROR " OBject required"
Dec 12 '07 #3

debasisdas
Expert 5K+
P: 8,127
run in debug mode and check which line is creating the error.
Dec 12 '07 #4

100+
P: 103
If e.Column <> sortColumn Then
'Set the sort column to the new column.
sortColumn = e.Column
Dec 12 '07 #5

VACEPROGRAMER
100+
P: 168
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
Dec 12 '07 #6

Expert 5K+
P: 8,434
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.
Dec 13 '07 #7

Expert 5K+
P: 8,434
Can someone explain to me what e represents?
Dec 13 '07 #8

QVeen72
Expert 100+
P: 1,445
Hi Killer,

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

Regards
Veena
Dec 14 '07 #9

Expert 5K+
P: 8,434
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?
Dec 15 '07 #10

QVeen72
Expert 100+
P: 1,445
Hi Killer,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
  2.  
  3. End Sub
  4.  
Regards
Veena
Dec 15 '07 #11

Expert 5K+
P: 8,434
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
Well, that's certainly not what it says in post #1.
Dec 16 '07 #12

QVeen72
Expert 100+
P: 1,445
Hi,

He must have Wrongly typed...

Regards
Veena
Dec 17 '07 #13

Expert 5K+
P: 8,434
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?
Dec 17 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.