VB.NET How iterate through a BindingSource
I have a BindingSource bound to a DataTable.
I use the BS Filter and would like to iterate the filtered dataset of the DataTable using the Binding开发者_C百科source.
I know I can do a MoveFirst and the MoveNext and each time using the BS.Position get the correct row in the underlying DataTable. But how do I know when the sets ends? I'm sure there must be such a property, but what is it?
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
Declare a row as:
Dim row As DataRowView = DirectCast(EmployeeListBindingSource.Item(count), DataRowView)
Then, access columns like:
row.Item(1).ToString
Compare it with if CompareStr <> row.Item(1).ToString then
I hope this helps.
BindingSource has Count property
精彩评论