VB.NET如何遍历BindingSource?

3
我有一个绑定到DataTable的BindingSource。
我使用BS Filter并希望使用Bindingsource迭代DataTable的过滤数据集。
我知道可以使用MoveFirst和MoveNext,并每次使用BS.Position获取底层DataTable中的正确行。
但是如何知道集合何时结束?我相信一定有这样的属性,但它是什么?
2个回答

3
Private Sub BindDataGridView()    
    Dim count As Integer = 0
    For count = 0 To EmployeeListBindingSource.Count - 1
        Dim RowIndex As Integer = dataGrdView1.Rows.Add()
        Dim row As DataRowView = DirectCast(EmployeeListBindingSource.Item(count), DataRowView)
        dataGrdView1.Rows(RowIndex).Cells(0).Value = row.Item(1).ToString
        dataGrdView1.Rows(RowIndex).Cells(2).Value = row.Item(0).ToString
    Next
End Sub

将一行声明为:

Dim row As DataRowView = DirectCast(EmployeeListBindingSource.Item(count), DataRowView)

然后,访问列的方法如下:
row.Item(1).ToString

if CompareStr <> row.Item(1).ToString then 进行比较。

希望这能有所帮助。


1

BindingSource有Count属性


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接