Freelancer77

I am trying desperately to figure out how to properly code databindings to textfields and comboboxes. My application selects from a variety of user-selectable databases, so I can't set up the data management tools (tableadapter, bindingnavigator, etc) in the designer, they have to be coded for initialization at runtime once a database is chosen.

Filling a dataset with the contents of a table works fine. What I am failing at is establishing the bindingsource for the columns of the table, and then binding each bindingsource successfully to a form control. An example table has 8 columns, for which 5 need to be bound to textboxes, and the other 3 to comboboxes.

I'm using the MS Jet 4.0 provider, since since they are all Access databases.

Help



Re: Visual Basic Express Edition Binding MSAccess table data to form controls at runtime

Bruno Yu - MSFT

Freelancer77,

Have you tried Control.DataBindings property that gets the data for the control like this:

TextBox1.DataBindings.Add(New Binding("Text", DataSet, "TableName.Field"))






Re: Visual Basic Express Edition Binding MSAccess table data to form controls at runtime

Freelancer77

Thank you very much, Bruno.

I have one major hurdle left. How can I navigate rows, or records, of data at this point Since my dataset(s) are not named until I have specified which Access database file I am working with, I can't declare a bindingnavigator in advance.

Once my form controls are properly bound to the dataset columns (thank you again), is there a way to declare and bind a bindingnavigator properly after the fact, or is there a way to simulate the same behavior





Re: Visual Basic Express Edition Binding MSAccess table data to form controls at runtime

Freelancer77

Prior to Bruno Yu's helpful post, I was in the middle of taking a different approach to my problem, and had gotten partial success.

Let's use the simplest table from my database as an example. There are four columns in the table, which is named TextFields:

- Frame_Number

- ID

- Time

- Text

I created an object class TextField, defining get/set properties for four strings to match the table columns. I then added the object class as a datasource in the designer. Right clicking on the class name in the Data Source window, I selected Details instead of DataGridView, then dragged the class onto the Textfields page of my tabbed form. This gave me a textbox for each data column, plus a bindingnavigator. Since each of the textboxes now has the bindingnavigator as it's bindingsource, it prevents me using Bruno's recommendation as he presented it.

But can I now bind the dataset columns to the bindingnavigator so that they are displayed in the correct textboxes, and controllable with the navigator I know that I can, I just don't know the right syntax.

Solving this will just about clear all of my current roadblocks. Thanks for any help.