.NET Combo Box
I have a form that I'm going to use to display a single staff information record. One of the fields is STAFF_TYPE_ID which is a number. The number corresponds to a number in another table (STAFF_TYPE) where there is text field that holds the description of the type (Manager, specialist, auditor, etc.) The field name is STAFF_TYPE_DESC.
I want to display the STAFF_TYPE_DESC in a combo box on the form but I want the combo box to be bound to the STAFF_TYPE_ID.
When I navigate through the records I want the description to change depending on the STAFF_TYPE_ID for the current record.
I want the user to be able to select a different value from the combo box (STAFF_TYPE_DESC listed) and have the corresponding STAFF_TYPE_ID be saved in the STAFF table for the current record.
I already know how to setup the form with a dataset, binding source, table adapter, manager, and navigator. I can't seem to figure out how to use a combo box to accomplish what I used to do VERY easily in VB6 and MS Access. I've banged my head on this all day and any help would be appreciated.
Before you start thinking that VB.NET is more complex than VB6, it's not. What you want to do is very easy. You simply have to bind the ComboBox twice: once to the child table and once to the parent table. If you're setting up the binding in the designer you need to set the ComboBox's DataSource to be the parent table, the DisplayMember to be the STAFF_TYPE_DESC column and the ValueMember to be the STAFF_TYPE_ID column. You then need to bind the SelectedValue property to the STAFF_TYPE_ID column of the child table, which you can do under the (DataBindings) node in the Properties window.
Thanks, that worked!! I had to do one additional thing. I removed the binding to the Text property. I guess when you drag and drop the field on to the form it automatically binds to the text property. It kept displaying the "ID" number until I removed that binding.
Tags for this Thread