Dim dvEmpolyees as New DataView(dtEmployees)
DataView dvEmployees = new DataView(dtEmployees);
Next, Sort it by calling the DataView's Sort Property:
dvEmployees.Sort = "DateOfHire"
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
dvEmployees.Sort = "DateOfHire, Department"
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.
dvEmployees.Sort = "DateOfHire, Department DESC"
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.
dvEmployees.Sort = "[Date Of Hire], Deparment"
dvEmployees.Sort = "[Date Of Hire], Department"
>>>after this bind dataview to grid.