Iterate databindings for bound controls on a form in VB 2008

I need to iterate through the bound controls on a form and pull out what field each bound control is connected to in an Access mdb. I am using Visual Studio 2008 VB. Any ideas?
glenn_grubbAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

melmersSenior Software Deveolper/ArchitectCommented:
Here is an example for you. i have tested it with a BindingSource.

The snippet will cycle throug all controls on the form.
When it has an binding it will store them in the 3 variables
myPropertyName                                 Bound Property
myPropertyBindField                            Bound Field of the Table
myPropertyBindDataSourceMember    Bound Table

you must only change the code to store the variables elswhere because every cycle they will be overwritten.
For Each myControl As Control In Me.Controls
            For i As Integer = 0 To myControl.DataBindings.Count - 1
                Dim myPropertyName As String
                Dim myPropertyBindField As String
                Dim myPropertyBindDataSourceMember As String
                myPropertyName = myControl.DataBindings.Item(i).PropertyName 'Bound Property
                myPropertyBindField = myControl.DataBindings.Item(i).BindingMemberInfo.BindingField 'Bound Field
                If TypeOf myControl.DataBindings.Item(i).DataSource Is BindingSource Then
                    myPropertyBindDataSourceMember = CType(myControl.DataBindings.Item(i).DataSource, BindingSource).DataMember 'Table
                Else
 
                End If
 
            Next
        Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
glenn_grubbAuthor Commented:
At first it didn't seem to work, but then I remember that you have to specifically call controls on a tabform (my controls are on pages in a tab form). The guts of the code I needed was this:
myPropertyBindField = myControl.DataBindings.Item(i).BindingMemberInfo.BindingField 'Bound Field
It returned the field bound to the control. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.