In order to use the built-in parameters area of the report, we would need to create a report Parameter that lists the column names. We can do that by creating a Business object that holds this for us:
public class ColumnSelector : DataTable
{
public ColumnSelector()
{
this.Columns.Add("displayText", typeof(string));
this.Columns.Add("sortColumn", typeof(string));
this.Rows.Add("Title", "Title");
this.Rows.Add("FirstName", "FirstName");
this.Rows.Add("LastName", "LastName");
this.Rows.Add("Phone", "Phone");
this.Rows.Add("Email Address", "EmailAddress");
this.Rows.Add("Not Sorted", "Not Sorted");
}
}
The last row is added simply for the sake of being able to show the report data unsorted if needed. We set the DisplayMember property of the parameter to displayText column and ValueMember to sortColumn column. Of course we should not forget to set the Visible property of the Report Parameter to true in order to show the parameter area above the ReportViewer.
Now is time to set the actual sorting: