【问题标题】:VB.NET How iterate through a BindingSourceVB.NET 如何遍历一个 BindingSource
【发布时间】:2011-01-11 08:14:22
【问题描述】:

我有一个绑定到 DataTable 的 BindingSource。

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

我知道我可以执行 MoveFirst 和 MoveNext,并且每次使用 BS.Position 都可以在基础 DataTable 中获取正确的行。 但是我怎么知道集合什么时候结束呢?我敢肯定一定有这样的财产,但它是什么?

【问题讨论】:

    标签: vb.net bindingsource


    【解决方案1】:

    BindingSource 具有 Count 属性

    【讨论】:

      【解决方案2】:
      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比较

      我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-05
        • 1970-01-01
        相关资源
        最近更新 更多