VB.NET 如何遍历 BindingSource

标签 vb.net bindingsource

我有一个绑定(bind)到 DataTable 的 BindingSource。

我使用 BS 过滤器并希望使用 Bindingsource 迭代数据表的过滤数据集。

我知道我可以执行 MoveFirst 和 MoveNext,每次使用 BS.Position 都可以在底层 DataTable 中获取正确的行。 但是我怎么知道集合什么时候结束?我确定一定有这样的属性,但它是什么?

最佳答案

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 进行比较

希望对您有所帮助。

关于VB.NET 如何遍历 BindingSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2170442/

相关文章:

vb.net - 如何将多行插入到 Access 数据库中?

c# - 在 RGB 和 HSB 颜色值之间切换的算法

winforms - "BindingSource cannot be its own data source"- 尝试从另一个类中的方法重置绑定(bind)源时出错

c# - BindingSource 获取当前行

c# - 有关 BindingSource 中 Find() 的帮助

.net - 如何让 Intellisense 显示枚举值的含义

c# - 下载需要使用 vb.net/c# 进行身份验证的文件?

regex - 使用正则表达式和 vb.net 从字符串中提取数字

c# - 当 DataSource 是 BindingList 时过滤 BindingSource

c# - Entity Framework : C# Winforms bindingsource delete on datagridview, 但仅将 isDeleted 字段标记为真(不删除)