Click here to Skip to main content
15,179,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to Visual basic and still in the process of learning all of the ins and outs of this language. I'm struggling with trying to get what's already in my lstbox that was read in from a text file to sort in Ascending and Descending order from using an dropdown menu. I've done this with Radio buttons, but they were on a datagrid and for some odd reason my code isn't doing anything this time.

What I have tried:

Dim ascNames() As String = IO.File.ReadAllLines("file.txt")

Dim ascQuery = From asc In ascNames
Order by ascName.Lendth Ascending, ascName Descending
Posted
Updated 24-Apr-18 3:09am

Issues are underlined:
VB
Dim ascQuery = From asc In ascNames
Order by ascName.Lendth Ascending, ascName Descending
...

wouls rather be
VB
Dim ascQuery = From asc In ascNames
               Order By asc.Length Ascending, asc Descending
               Select asc

- Variable name is asc, its type is string.
- It is sorted by ascending length (Length property of string object) and descending value.
- There must be a Select statement.

Kindly.
   
Comments
Maciej Los 24-Apr-18 7:23am
   
+5!
In addition to soultion #1 by phil.o[^], a lambda version of solution:

VB
Dim ascQry1 = ascNames.OrderBy(Function(x) x.Length).ThenByDescending(Function(x) x)


For further details, please see:
Enumerable.OrderBy(TSource, TKey) Method (IEnumerable(TSource), Func(TSource, TKey)) (System.Linq)[^]
Enumerable.OrderByDescending(TSource, TKey) Method (IEnumerable(TSource), Func(TSource, TKey), IComparer(TKey)) (System.Linq)[^]
Enumerable.ThenBy Method (System.Linq)[^]
Enumerable.ThenByDescending Method (System.Linq)[^]

Good luck!
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900