2013-01-23 16 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來更新,但問題已解決。