defaultview.sort ignoring the last row in the defaultview

I created a table, created a dataview, and sorted the dataview. I then populated the table with three rows of data and all was good. I then changed one of the fields (Hours) in one of the rows which SHOULD HAVE caused it to re-sort, but it did not re-sort. It seems to only affect the last row of the dataview. I tried removing and re-applying the sort condition with no luck. Any idea what is up here?

Function CreateStoreHours() As DataTable
    StoreHours.Columns.Add("Store", GetType(String))
    StoreHours.Columns.Add("Hours", GetType(Double))
    StoreHours.DefaultView.Sort = "Hours ASC"
    dgvStoresHours.DataSource = StoreHours
End Function

'Here I popluated the grid with three records. All were sorted correctly.

For v = 0 To StoreHours.DefaultView.Count - 1
    If row("Store") = StoreHours.DefaultView(v).Item("Store") Then
        Match = True
        StoreHours.DefaultView(v).Item("Hours") = StoreHours.DefaultView(v).Item("Hours") + row("Hours")
        'The Hours field gets adjusted properly, but it gets moved to the last record even 
        ' though it should be sorted as the second record of three. This is also where I tried
        ' the un-sort and re-sort with no luck.
        Exit For
    End If
Next

Answers


Found the answer on another forum...

I had to update the underlying datatable directly. This ensures that the changes are reflected in the dataview. Not sure why we can't just update via the defaultview, but the problem is fixed.


Need Your Help

Foreach and while loop prints the same value

php mysql foreach while-loop

I'm trying to get the info from each user, this is what I am trying:

class=“mytest anothertest”…what is anothertest?

html css

Trying to learn html/css. I've been looking at the html & css files of a couple different websites that have something along the line of:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.