VB.Net - Lists - SortedList

The sorted list object is used to contain a list that is somehow sorted alphabetically.

Sample of creating a list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  Public shared Function WhichColumns2SortedList (whichColumns As String) _
As SortedList(of String, si.ui_lv_colspec)

'
' whichColumns could be a string that looks like this
' A|Hello;Z|ZHello;C|Common Data
'
Dim columnsToGenerate As New SortedList(Of String, si.ui_lv_colspec)

Dim args() As String _
= whichColumns.Split(";"c)
For Each arg As String In args
Dim dta() As String = arg.Split("|"c)

Dim aControlSpec As si.Ui_Lv_ColSpec _
= New si.Ui_Lv_ColSpec(arg)

columnsToGenerate.Add(CDbl(dta(0).ToUpper, aControlSpec)
Next
return Columnstogenerate
End Function

This function will take a string (something like A|Hello;Z|ZHello;C|Common Data) and split it by semicolons. (In our example into 3 pieces). Then it will take those splits and turn each one of those into pieces. (in the first one there will be A and Hello). An object is created of type si.Ui_Lv_ColSpec. It’s initialized with the original piece (ex A|Hello). Then the object, and the first part of the object (A in the A|Hello) will be added to the sorted list.

The result is a sorted list. That list will be sorted by the first argument of the add method.

To step through the list you would do something like this

1
2
3
4
5
6
   for each  de as KeyValuePair(of double, si.Ui_Lv_ColSpec) In ColumnsToGenerate
dim aControlSpec as si.Ui_Lv_ColSpec _
= de.Value

print aControlSpec.Title
next

If you did started off with an input string of (A|Hello;Z|ZHello;C|Common Data) the output of this would be:

  • Hello
  • Common Data
  • ZHello