I populate a DataTable, then sort the DefaultView of that DataTable. When I set the DataTable as the source for my report, the sort doesn’t work. In case it helps, here is the code (GetData returns a valid DataTable):
Dim dt As DataTable = a.GetData(Parm1, Parm2, Parm3)
If rbtSortByField1.Checked Then
dt.DefaultView.Sort = "Field1 ASC"
ElseIf rbtSortByField2.Checked Then
dt.DefaultView.Sort = "Field2 ASC"
ElseIf rbtSortByField3.Checked Then
dt.DefaultView.Sort = "Field3 ASC"
End If
rpt.SetDataSource(dt.DefaultView.Table)
'This also doesn't work
'rpt.SetDataSource(dt)
ASSUMING this is a Crystal Report…
See this article. You can’t sort on the datasource, you need to have the report do the sorting.
http://it.toolbox.com/blogs/coding-dotnet/sorting-the-fields-in-crystal-report-programmatically-16201
Also covered here:
http://msdn.microsoft.com/en-us/library/ms225717.aspx