Take the 2-minute tour ×

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
share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer


