R
Raymond Lewallen
I have a dataview in which the sort property will not sort the dataview.
Here's is a simple scenario similar to what I am doing:
Class Foo
Private Function Retrieve() As DataView
' Returns a DataView with 2 columns and 3 rows
Dim ADOHelper As New DAL.ADOHelper
Return ADOHelper.GetMyDataview()
End
Public Sub ShowDataView()
Dim dv As DataView = Retrieve()
' dv's table has 2 columns, integer called "A" and string called "B"
' dv has 3 rows as follows:
' 2 "DEF"
' 3 "GHI"
' 4 "JKL"
Dim drow As DataRow
drow = dv.Table.NewRow()
drow("A") = 1
drow("B") = "ABC"
dv.Table.Rows.Add(drow)
' HERE IS THE PROBLEM. SORT DOES NOT SORT.
dv.Sort = "A"
For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A").ToString(),
" - ", eachRow.Item("B").ToString()))
Next
End Class
When calling Foo.ShowDataView(), the output will be the following:
2 - DEF
3 - GHI
4 - JKL
1 - ABC
Any ideas on why the sort is not working? Is there something else I am
missing? I've applied sorts to all kinds of dataviews before and never had
this happen, and I've spent 6 hours trying to figure out why it will not
work. I've even tried sorting on column "B", and tried sorting DESC on each
column too. Nothing seems to work.
Any help is greatly appreciated.
Here's is a simple scenario similar to what I am doing:
Class Foo
Private Function Retrieve() As DataView
' Returns a DataView with 2 columns and 3 rows
Dim ADOHelper As New DAL.ADOHelper
Return ADOHelper.GetMyDataview()
End
Public Sub ShowDataView()
Dim dv As DataView = Retrieve()
' dv's table has 2 columns, integer called "A" and string called "B"
' dv has 3 rows as follows:
' 2 "DEF"
' 3 "GHI"
' 4 "JKL"
Dim drow As DataRow
drow = dv.Table.NewRow()
drow("A") = 1
drow("B") = "ABC"
dv.Table.Rows.Add(drow)
' HERE IS THE PROBLEM. SORT DOES NOT SORT.
dv.Sort = "A"
For Each eachRow As DataRow In dv.Table.Rows
Console.WriteLine(String.ConCat(eachRow.Item("A").ToString(),
" - ", eachRow.Item("B").ToString()))
Next
End Class
When calling Foo.ShowDataView(), the output will be the following:
2 - DEF
3 - GHI
4 - JKL
1 - ABC
Any ideas on why the sort is not working? Is there something else I am
missing? I've applied sorts to all kinds of dataviews before and never had
this happen, and I've spent 6 hours trying to figure out why it will not
work. I've even tried sorting on column "B", and tried sorting DESC on each
column too. Nothing seems to work.
Any help is greatly appreciated.