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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to work with sortedList

Status
Not open for further replies.

yosie2007

Technical User
Jun 23, 2007
46
US
I would like to have all the quarter for 2007 together like this. How can I fix this. thanks
Q1-2007
Q2-2007
Q3-2007
Q4-2007
Q1-2006
Q2-2006
Q3-2006
Q4-2006
Q1-2005
Q2-2005
Q3-2005
Q4-2005


right now in my dropdown it displays like this
Q1-2005
Q1-2006
Q1-2007

Q2-2005
Q2-2006
Q2-20066


Sub QuarterSelector()

Dim QSelector As SortedList
QSelector = New SortedList
QSelector.Add("1-2007", " Q1-2007")
QSelector.Add("2-2007", " Q2-2007")
QSelector.Add("3-2007", " Q3-2007")
QSelector.Add("4-2007", " Q4-2007")
QSelector.Add("1-2006", " Q1-2006")
QSelector.Add("2-2006", " Q2-2006")
QSelector.Add("3-2006", " Q3-2006")
QSelector.Add("4-2006", " Q4-2006")
QSelector.Add("1-2005", " Q1-2005")
QSelector.Add("2-2005", " Q2-2005")
QSelector.Add("3-2005", " Q3-2005")
QSelector.Add("4-2005", " Q4-2005")
QSelector.Add("", "--Quarters--")
ddlQuarter.DataSource = QSelector
ddlQuarter.DataValueField = "Key"
ddlQuarter.DataTextField = "Value"
ddlQuarter.DataBind()

End Sub
 
I change it to this and seems to work ok...please let me know if there is another better way ...thanks

Sub QuarterSelector()

Dim QSelector As SortedList
QSelector = New SortedList
QSelector.Add("2007-1", " Q1-2007")
QSelector.Add("2007-2", " Q2-2007")
QSelector.Add("2007-3", " Q3-2007")
QSelector.Add("2007-4", " Q4-2007")
QSelector.Add("2006-1", " Q1-2006")
QSelector.Add("2006-2", " Q2-2006")
QSelector.Add("2006-3", " Q3-2006")
QSelector.Add("2006-4", " Q4-2006")
QSelector.Add("2005-1", " Q1-2005")
QSelector.Add("2005-2", " Q2-2005")
QSelector.Add("2005-3", " Q3-2005")
QSelector.Add("2005-4", " Q4-2005")
QSelector.Add("", "--Quarters--")
ddlQuarter.DataSource = QSelector
ddlQuarter.DataValueField = "Key"
ddlQuarter.DataTextField = "Value"
ddlQuarter.DataBind()

End Sub
 
That's one way of doing it but not the correct way.

You should make a class that takes the values (two properties) and then implement the icomparable interface. This will then take care of the sorting for you. That way you can just use an ordinary list or a generic list and use its sort method or the reverse method if you want to reversesort it.

Christiaan Baes
Belgium

"My old site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top