BindingSource Question

thrift_store_angel

New member
Joined
Dec 5, 2010
Messages
1
Programming Experience
Beginner
I am sure this is the probably the easier thing ever and the only reason I couldn't find a clear answer to it anywhere else is because it is assumed that everyone already knows this, but I am an absolute beginner, just taking a beginning VB.NET class and I have no clue how to do this. I have a BindingSource that is filtered down to one row with maybe 8 or so columns. I need to store the data in those columns in variables. For example say one of the columns is age and in this row the value in age is 45. I need to be able to do whatever gets me Dim AgeInt As Int = (how do I get 45 in here?).

I know, really simple I am sure, but any help would be much appreciated! :eek: Thanks!
 
The BindingSource is a list, so you can loop through it using a For or For Each loop to access each item, just like other lists. You can also access an item by index. If you want the first item, which will be the only item in your case, you simply index the BindingSource using 0 as the index.
 
Dim ageInt As Integer = DirectCast(bindingsource(0)("age"), Integer)

possibly:
Dim ageInt As Integer = DirectCast(bindingsource.List(0).Item("age"), Integer)

When working with bindingsources I'm normally using them on top of TYPED datasets, so I make a property:
VB.NET:
ReadOnly Property CurrentRow as MyTypedDataRow
  Get
    Return DirectCast(DirectCast(myBindingsource.Current, DataRowView).Row, MyTypedDataRow)
  End Get
End Property
Then just use it like:

CurrentRow.Age

Assuming the typed datatable has a column called Age
 
Back
Top