Sort a listbox by a nondisplayed object field??

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

I populate a ListBox with Objects (not Strings) that has a String field
(which is displayed) and an Integer field (which is not displayed).

I need to have the displayed items in the Listbox sorted. But sorted by the
Integer field not the displayed String.

Is there some way I can do that (in much the way a ListView can be sorted by
any column)

Thanks
 
Hi,

Two ideas:

1. populate a multidimensional array or arraylist or hash table with the 2
elements (the string and the integer); when the user clicks a button, sort
as specified and repopulate the listbox.
2. if you are sorting it as part of a static listbox in a form, thus no
user interaction, you can use the idea above to sort and then populate once
in the form's load event.

HTH,

Bernie Yaeger
 
Bernie, I did implement this and replied. Don't know where the reply when.

Thanks

Bernie Yaeger said:
Hi,

Two ideas:

1. populate a multidimensional array or arraylist or hash table with the 2
elements (the string and the integer); when the user clicks a button, sort
as specified and repopulate the listbox.

Thanks, I used ArraySort to sort 2 single dimension arrays. Work good.
 
Hi,

No problem; glad to help.

Bernie

Just Me said:
Bernie, I did implement this and replied. Don't know where the reply when.

Thanks

the

Thanks, I used ArraySort to sort 2 single dimension arrays. Work good.
 
Bernie Yaeger said:
Hi,

Two ideas:

1. populate a multidimensional array or arraylist or hash table with the 2
elements (the string and the integer); when the user clicks a button, sort
as specified and repopulate the listbox.


This would work for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top