Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SortOrder in ListBox

Status
Not open for further replies.

Jefftopia

Programmer
Jul 30, 2002
104
US
I have a form with two combo boxes a command button and a list box. The first combo box contains the names of the column headers in my list box. The second combo box contains the choices of Ascending or Descending.

When the user clicks the command button (labeled "Sort"), I would like the listbox data to be sorted according to the column selected in the first combo box in Ascending or Descending according to selection made in second combo box.

My listbox is populated using a string with tabs inserted to give a columnar appearance. I would like to accomplish this through the use of an array as opposed to simply requering the database. Here is were I stand:

'Save contents of list box to an array.
Dim i As Integer, arrInfo() As String

ReDim arrInfo(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
arrInfo(i) = List1.List(i)
Next

'Clear list box.
List1.ClearBox = True

'Set SortOrder.
'++++++++THIS IS WHAT I AM MISSING+++++++++

'Add items back to list box.
For i = 0 To UBound(arrInfo)
List1.AddItem arrInfo(i)
Next
 
Is there a really good reason not to requery the database? Or is this just an academic exercise?

If real, requery

If academic, look up ShellSort or Bubblesort on Google
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Some use an invisible Listbox with Sorted=True, fill it with items constructed according to the desired "keys", then recreate the orignal list box, Sorted=False. Items are taken from the front or the back of the sorted listbox according to ascending or descending preference. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
think i'll go about sorting by requerying. don't have time to go the bubblesort acadamia route.

thanks..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top