Design Time:
- Drag and drop a DatGrid on the form.
- Set AllowSorting property of the grid to True.
- Set AutogenerateColumns property of the grid to False.
- Add bound columns to datagrid and set their properties as follows. The sortexpression property refers to the name of column in database table.
Note: Employees table from Northwind database is being used to illustrate the purpose.
DataTextField |
Header Text |
Sort Expression |
EmployeeID |
Employee ID |
EmployeeID ASC |
LastName |
Last Name |
LastName ASC |
FirstName |
First Name |
FirstName ASC |
Title |
Title |
Title ASC |
City |
City |
City ASC |
Country |
Country |
Country ASC |