Dynamically linkd drop down fields

JMichaels22

New member
Joined
Jul 6, 2006
Messages
1
Programming Experience
Beginner
I am fairly new to programming and working on a side project for work. I am building a form and I would like to have drop down fields linked somehow.

For example: I have a SQL db with product information like SKU and Description. How do you link them so when a SKU is selected it automatically populates the description and vice versa?

Am I going about this wrong?

Thanks for helpin a new-b
=)

-J
 
quick example:

In my app I have 2 datatables. One is for person details, the other is for their Title i.e. Mr Mrs Miss Dr Rev Sir Madam etc.

so a person record for Mr John Smith might look like:

TITLE_ID, NAME
1, John Smith


The lookup table for titles is called LUT_TITLE and has data like:

TITLE_ID, TITLE_DESC
1, Mr
2, Mrs




On my form, I drop a combobox, and just the PERSON data table. for the combobox on the form, in the Properties window i go to the (DataBindings) entry at the top (my properties are sorted alphabetically, you might have to hunt for this if yours are grouped) and expand it.
In there I see a SelectedValue property, and this, I set to PERSONDataTable.TITLE_ID
The designer will help you with this.

My lookup tables are held in a module, they are populated one time and used throughout the app. If you added your lookup table to the form too, then you change the wording slightly here but the spirit remains the same:


Now in my Form_Load event handler I write:

VB.NET:
TITLE_IDCombobox.DataSource = Universe.LookupTablesDataSet.LUT_TITLE
TITLE_IDCombobox.DisplayMember = "TITLE_DESC"
TITLE_IDCombobox.ValueMember = "TITLE_ID"



Universe is a module - i only need one instance and its where i put all the utility stuff like saving and loading prefs, constant strings, enums etc. LookupTablesDataset is a dataset of all the lookup tables in my app. Its filled everytime Universe.RefreshLUTs is called (called upon startup of the app)
LUT_TITLE is the lookup table for title. After refreshing it contains 1, Mr.. 2, Mrs and so on


Now then i show my form, i can pick an entry from the list.. Mr is seen, but 1 is what is transmitted into the SelectedValue property, which is bound to my person datatable.. so i see Mr, but i save 1

REMEMBER:
combo by default are textbox free entry with a list. change the style to DropDownList to make sure the user cannot type into the box

Another handy thing if you make the DropDownStyle to Simple then the arrow goes away. I use this in datagridviews for when i want a column of Mr Mrs Dr etc with making them look like text boxes
 
Last edited by a moderator:
if you are using bindingsources, then thats what you will bind in the selected value of the combobox

for more info search google for "data walkthroughs" and look at the result from microosft
 
Back
Top