473,769 Members | 2,220 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.S ort() in this instance?

Do I need to do my own quicksort?
Nov 20 '05 #1
4 18209
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************ *************@r eallyidont.com> schreef in
bericht news:bq******** ***********@new s.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.S ort() in this instance?

Do I need to do my own quicksort?

Nov 20 '05 #2
* "Robin Tucker" <id************ *************@r eallyidont.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.ObjectC ollection, 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.pl ease.leadit.be> wrote in message
news:uq******** ******@TK2MSFTN GP12.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************ *************@r eallyidont.com> schreef in
bericht news:bq******** ***********@new s.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.S ort() 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("Ro bbedoes", "Marsupulan ie")
ListBox1.Items. Add(li)
li = New clsListItem("Su ske", "wiske")
ListBox1.Items. Add(li)
li = New clsListItem("Lu cky 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
4557
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
2933
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 something serverside with them) Like this: ( represents a text or select filed) an item something else a differnt thing the other
11
1684
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
1207
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 be appreciated. 2005 November
9
4446
by: incredible | last post by:
how to sort link list of string
9
2011
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
2496
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 in a list step instances A step instance contains variables: name, startTime etc and startTime is stored as a string %H:%M:%S
2
14772
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 the DataError event and just doing nothing in the circumstance that caused the error. Here's my situation: I would like to allow the user to EITHER select an item from the ComboBox (in a DataGridView) OR type in a new value of their own.
12
5096
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 put them before the surname, it is the first String of the every line in the listBox. My code under the sortBySurname is private void sortBySButton_Click(object sender, EventArgs e) { contactListBox.Items.Clear(); ...
0
1455
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 out the Results in the format below. I have enclosed my code and it works, but the problem happens when there are duplicate values, which occurs when you use SortedList(). I would GREATLY APPRECIATE it if someone could PLEASE Modify this Code or...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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 we have to send another system

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.