• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

sorting a hashtable or a dictionary


I have a dataset where each row represents the results for a team in a rugby  league table. It has columsn for team name, total points, goal difference, goals for and goals against. I was wondering what would be the easiest way to sort this dataset so that the teams were ordered in the correct order for the table (e.g highest points at the top, if 2 teams have the same points then the one with highest goal difference is second)

This might be a basic question. I'm asking because I am interested in knowing an efficient way of doing this. I once asked something like this and got accused of doing homework. This isn't homework. I'm 32 and its for the rugby world cup :)

many thanks in advance
1 Solution
Wayne Taylor (webtubbs)Commented:
Hello andieje,

Do you wish to sort a dataset, or a hashtable/dictionary?

To sort a dataset's table, you'd use a DataView....

        Dim dv As New DataView(ds.Tables(0))
        dv.Sort = "[Total Points]"


The easiest way to sort a datatable is to use "ORDER BY [Fieldname]" in the SQL that generates it.  If that isn't an option, you can set up a DataView which represents a view of the DataTable that you can sort, filter, etc.


Dim dv as New DataView(MyDataTable)
dv.Sort("Fieldname Asc")  'Ascending sort.

DataView sort:

Then you can use the dataview as a data source.  If you search the MSDN for dataview, you'll find some good stuff there.
Bob LearnedCommented:
You don't even need to create a new DataView:

DataSet1.Tables(0).DefaultView.Sort = "Name"
Me.dg.DataSource = DataSet1.Tables(0).DefaultView

andiejeAuthor Commented:
Hi Paul

You're right - sorting is a database thing!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now