473,503 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I sort the items in a list box?

How do I sort the items in a list box?

I am using a class derived from IComparer to sort items on columns in a
ListView, but the ListBox doesn't support this kind of facility. The
"items" in my list box aren't just strings, they are a class I have defined
for each list item. There is a comparitor function, but how can I write -
ListBox.Items.Sort() in this instance?

Do I need to do my own quicksort?
Nov 20 '05 #1
4 18189
Hi

I wrote a generic Comparer class for sorting collections of objects. Check
out the code:
http://weblogs.asp.net/jan/posts/6479.aspx
--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan

"Robin Tucker" <id*************************@reallyidont.com> schreef in
bericht news:bq*******************@news.demon.co.uk...
How do I sort the items in a list box?

I am using a class derived from IComparer to sort items on columns in a
ListView, but the ListBox doesn't support this kind of facility. The
"items" in my list box aren't just strings, they are a class I have defined for each list item. There is a comparitor function, but how can I write -
ListBox.Items.Sort() in this instance?

Do I need to do my own quicksort?

Nov 20 '05 #2
* "Robin Tucker" <id*************************@reallyidont.com> scripsit:
How do I sort the items in a list box?


Sort them before adding them to the control.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Hi,

Thanks for this - although I have written a "generic" comparer (well it
compares 2 instances of the objects I want it to compare, on the keys I want
it to compare on). I'm using this in the ListView to sort, but the ListBox
is different. With the list view, all I need to do is set the comparer when
the user clicks on a column and it sorts automatically. Listbox's are more
primitive. I just have a ListBox.ObjectCollection, which doesn't support
sorting, so I have to do it myself somehow. Just thought there might be a
quick and easy way like with the ListView.

Cheers
"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
Hi

I wrote a generic Comparer class for sorting collections of objects. Check
out the code:
http://weblogs.asp.net/jan/posts/6479.aspx
--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan

"Robin Tucker" <id*************************@reallyidont.com> schreef in
bericht news:bq*******************@news.demon.co.uk...
How do I sort the items in a list box?

I am using a class derived from IComparer to sort items on columns in a
ListView, but the ListBox doesn't support this kind of facility. The
"items" in my list box aren't just strings, they are a class I have

defined
for each list item. There is a comparitor function, but how can I write - ListBox.Items.Sort() in this instance?

Do I need to do my own quicksort?


Nov 20 '05 #4
Cor
Hi Robin,

With a little bit changed the code that EricJ did supply us today I got with

Dim li As clsListItem = New clsListItem("Robbedoes", "Marsupulanie")
ListBox1.Items.Add(li)
li = New clsListItem("Suske", "wiske")
ListBox1.Items.Add(li)
li = New clsListItem("Lucky Luke", "Joly Jumper")
ListBox1.Items.Add(li)
ListBox1.Sorted = True

On screen as:
Lucky Luke,
Robbedoes
Suske

I hope this is something for you,

Cor
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4537
by: Valkyrie | last post by:
I have a list of tuples, and one of the fields in the tuple is score. So how can I sort the list by the score? Thanks in advance
7
2909
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing...
11
1652
by: Shi Mu | last post by:
I have a list like ,,,]. How can I sort the list based on the second value in the item? That is, I want the list to be: ,,,]
1
1198
by: Torbjorn Pettersen | last post by:
This one is related to my previous question. My (Access) database contains events. I'd like to sort and list by month and year, like the example under here. Any tips on how to do this would...
9
4398
by: incredible | last post by:
how to sort link list of string
9
1986
by: active | last post by:
Can you see why this does not sort the list? It displays OK but is not sorted Thanks for any help
5
2486
by: cjt22 | last post by:
Hi there I am fairly new to Python and have not really used regular expressions before (I think this might be needed for my query) and wondered if you could help I have a step class and store...
2
14717
by: =?Utf-8?B?RHJEQkY=?= | last post by:
I understand that the Value put into a DataGridViewComboBoxCell has to be a member of the Items list or an exception is thrown. I also understand that you can override that exception by handling...
12
5045
by: Nzsquall | last post by:
Hi, I am having trouble sorting a client contact lists by their surname. Every time when I press the "sort by surname button, it always appear alphabetical order by clients' first name, because I...
0
1442
by: Joe Cagg | last post by:
I have looked All over the Internet to try and find an example of How to fix the following. How to Sort a List in Desending Order by the "Value" and Sort the Duplicates by the "Key" ? Then Print...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.