Combo Boxes with Databases and Forms that do cool things

Morn

Active member
Joined
Dec 4, 2006
Messages
40
Programming Experience
Beginner
Hi there,

I am new to VB and am trying to produce a form that will read the values from a table in a MS Access DB. The values are the counties in England.

I have made the connection in the form_Load sub, but am unable to find the particular coding to make the values enter themselves into the combo box when the form loads.

If anyone can help me on this I would be grateful.

My second question is a little tricker, I am trying to get users to enter the amount of people traveling on a holiday by selecting a value from a combo box. (1-10)

Once they select the value and select go, the page is refreshed with a correct number of textboxes so that the user can enter the travelers name, date of birth, and gender + any activities the traveler may want.

So in other words you select 8 from the combo box when the form loads, then you click go, and then below the combo box in another panel, a name text box, DofB combo box set, and a activity radio set appear 8 times one below the other relating to the eight users.

I hope this makes sense.

Thanks In advanced.

Kind Regards
Graham
 
Once you have the data in a DataTable you can assign that table to the DataSource property of the ComboBox. You then assign the name of a column to the DisplayMember property of the ComboBox and the data from that column will be displayed in the drop-down list.

In .NET 2.0 it is recommended to also use a BindingSource. You would assign the DataTable to the DataSource property of the BindingSource, then assign the BindingSource to the DataSource property of the ComboBox. Everything else is the same, but the BindingSource makes manipulating the data somewhat easier.

Note that you can also assign the name of a column to the ValueMember property of the ComboBox. The most usual use for that is for the primary key column. That way when the user selects a record using the friendly name you can still get the corresponding primary key from the SelectedValue property.

I disagree with how you're doing things with the variable number of TextBoxes. It is certainly possible but I would use a DataGridView instead. Then the user just enters as many people as they want. Once they're done you get the number of people from the number of rows, plus you would bind a DataTable to the grid so your data is ready to save to a database without any further processing.
 
Hi thanks for your reply,

I think that I get the general idea of what you are saying just some questions to clarify:

1) DataTable, I have a coded connection string to the database that simply opens and closes the database connection. The code is:

Dim connectiontoDB As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\holiday.mdb")
connectiontoDB.Open()

connectiontoDB.Close()

From here I am a little hazy in what you are suggesting, any elaboration would be greatly appreciated.

2) DataGridView, is there anywhere that you can point me to read about these, the standard Google search provides info that I quiet frankly don’t get. Are you suggesting that once the the new form is loaded, that say 10 (being the max travelers) textboxes etc.... open and the user just completes the amount that they require? So therefore not needing to pres-elect the number of travelers?

I am sorry for the simple nature of these queries, my textbook and lecture notes in no way cover this.

Thanks in advance

Graham
 
Back
Top