VB.NET
Dim dvEmpolyees as New DataView(dtEmployees)
C#
DataView dvEmployees = new DataView(dtEmployees);
Next, Sort it by calling the DataView's Sort Property:
VB.NET
dvEmployees.Sort = "DateOfHire"
C#
dvEmployees.Sort = "DateOfHire";
Compare using 2 lines of code with the effort it would take to requery the database and then refill a table? Few things are so cleear cut.
Now, what if you wanted to sort it by multiple fields, say DateOfHire and Department
VB.NET
dvEmployees.Sort = "DateOfHire, Department"
C#
dvEmployees.Sort = "DataOfHire, Department";
Just as simple, right?
Now, lets say that you wanted DateOfHire sorted by normally, but you wanted department sorted in Descending Order. Piece of cake.
VB.NET
dvEmployees.Sort = "DateOfHire, Department DESC"
C#
dvEmployees.Sort = "DateOfHire, Department DESC";
There's one other thing you might want to be aware of. Every now and then, you might be confronted with a case where you have Spaces in your field names or Reserved words. Typically, the 'correct' approach is to go back and change them in the database ASAP. There is so much downside to having fields named like this, but I know, there are a lot of people who are in love with their naming conventions even if there's a ridiculously high cost associated with such terrible habits. Anyway, if you can't change the names of the column, you can use the "[]" to get it to work.
VB.NET
dvEmployees.Sort = "[Date Of Hire], Deparment"
C#
dvEmployees.Sort = "[Date Of Hire], Department"
>>>after this bind dataview to grid.