.Net to Sort DataGridView Programmatically

Today my friend has asked me a good question, he want to ensure the data on the DataGridView is in the correct sorting order. He is wondering how to achieve that. I still remember, I have tried something similar before.

Here it is what you need to do:

  1. We have a DataGridView called “dgv_Membership
  2. This table contains “Surname“, “First Name“, “DoB“, “Screen name
  3. We would like to sort the table by DoB (Date Of Birth) before we process that data.

What we need to do it to use the Sort method on the DataGridView control
dgv_Membership.Sort(dgv_Membership.Columns(“Dob”),System.ComponentModel.ListSortDirection.Ascending )

GridViewName.Sort(“GridViewColumn that you want to sort by”, “Sorting Direction”)

Good Luck

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.