Dataview Sort not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Below is the code. This code should sort Subjects by SeqNo or LastName. But
it has no affect on the order. The order remains the same as original
dataset (ds). What I am doing wrong?

WR

Dim dvS As New DataView
Dim iPerson_ID As Int32
Try
dvS = ds.tblSubject.DefaultView
Select Case optOrderBy.Value
Case "SeqNo"
dvS.Sort = "SeqNo"
Case "LastName"
dvS.Sort = "LastName"
Case "Entered"
End Select
 
WR,

You are missing showing us some important code here. First of all it will
not compile because of the "Try", so if I saw the whole try/catch block there
may be something in there causing the problem. Secondly, we do not see where
or what the view is being bound to. It is important to rebind the view to
the datasource after it changes.

Jerry
 
Thank You for the reply . . .

This is only a snippet of the code, I didn't include the rest because it is
not revelant. Therefore you do not see the catch and end try statement. The
missing code simply iterates through this dvS printing out an order form for
each subject in the order the customer has selected. It compiles and run
fine; it just doesn't change the sort order.

Here is the example in the help file -- where is the rebinding happening in
this example?

Private Sub SortByTwoColumns()
' Get the DefaultViewManager of a DataTable.
Dim myDataView As DataView
myDataView = DataTable1.DefaultView
' By default, the first column sorted ascending.
myDataView.Sort = "State, ZipCode DESC"
End Sub

PS: To make things work I simply did this:

Dim rowsS() As dsMailEvent.tblSubjectRow
Try

Select Case optOrderBy.Value
Case "SeqNo"
rowsS = ds.tblSubject.Select("", "SeqNo ASC")
Case "LastName"
rowsS = ds.tblSubject.Select("", "LastName ASC")
Case "Entered"
rowsS = ds.tblSubject.Select("", "")
End Select

I simply use rowsS where I used dvS and everthing works. I just don't
understand why the dataview will not work.

WR
 
Back
Top