'在DataGrid的AllowSorting值为True的情形下,利用CurrentRowIndex来取DataTable中相应的Row是不大妥当的。
'在随意中进行了某列排序后,CurrentRowIndex与DataTable的“CurrentRowIndex”就有可能不相符,
'DataTable1.Rows[DataGrid1.CurrentRowIndex]可能并不是你真正要的。
'稳妥的方法可以这样:
Dim MyCurrencyManager As CurrencyManager
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'......
MyCurrencyManager = Me.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
CType(MyCurrencyManager.Current, DataRowView).Row.Delete()
End Sub
博客指出在DataGrid的AllowSorting为True时,用CurrentRowIndex取DataTable中相应的Row不妥,排序后两者可能不相符。并给出稳妥方法,通过CurrencyManager来操作,如在Form1_Load中设置,在Button2_Click中实现删除行操作。
9756

被折叠的 条评论
为什么被折叠?



