2013-01-23 15 views
1

我创建了一个表,创建了一个数据视图并对数据视图排序。然后我用三行数据填充表格,一切都很好。然后,我在其中一个应该使其重新排序的行中更改了一个字段(小时数),但没有重新排序。它似乎只影响数据视图的最后一行。我尝试删除并重新应用排序条件,但没有运气。任何想法是什么在这里?defaultview.sort忽略默认视图中的最后一行

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 

回答

0

找到另一个论坛上回答......

我必须直接更新基础DataTable。这可确保更改反映在数据视图中。不知道为什么我们不能通过defaultview来更新,但问题已解决。