Using BindingNavigator and ComboBox of data bound items

G

Guest

I'm new to .net 2.0 and I'm trying to figure out the best way to create a
form that has a couple of controls and one of the controls is a combo box
with a data bound list of items from another table.

To understand the problem more, consider using the AdventureWorks2000
database. I want a simple form that shows FirstName, LastName, and Shift.
Instead of the ShiftID, I want the shift name from the Shift table to be
displayed.

Here's what I've tried:
1. Create dataset with Employee table and Shift Table.
2. Drag employee FirstName and LastName on the form
3. A BindingNavigator and BindingSource were created when FirstName was
dragged onto the form.
4. Change ShiftID to a comboBox and drag it onto the form
5. Configure the combobox to bind to the ShiftBindingSource
6. Select ShiftId as the Value Memeber.
7. Select Name as the Display Member


I have two problems:
1. Once the data item list is displayed in the combobox, the Display Member
(Shift.Name) is not the right display member for the display value
(employee.ShiftId). Do I have to synchronize the two BindingSources? Do I
have to use only one BindingSource and join Employee and Shift in one query?
Something else?

2. How do I make ShiftID get inserted or updated in the employee table from
a selection in the comboBox?
 
B

Bart Mermuys

Hi,

bds said:
I'm new to .net 2.0 and I'm trying to figure out the best way to create a
form that has a couple of controls and one of the controls is a combo box
with a data bound list of items from another table.

To understand the problem more, consider using the AdventureWorks2000
database. I want a simple form that shows FirstName, LastName, and Shift.
Instead of the ShiftID, I want the shift name from the Shift table to be
displayed.

Here's what I've tried:
1. Create dataset with Employee table and Shift Table.
2. Drag employee FirstName and LastName on the form
3. A BindingNavigator and BindingSource were created when FirstName was
dragged onto the form.

4. Click on the arrow next to the Shift table ( not ShiftID )
(4.1 If you don't see an option for combobox then click customize and check
combobox)
4.2 Change Shift table to combobox

5. Drag Shift Table onto form, you should see a combobox on the form

6. Open combobox properties
6.1 Check if DataSource/ DisplayMember and ValueMember are correct
6.2 Expand (DataBindings)
(6.3 If you see a binding for Text then click on the arrow and set the
binding to None)
6.4 Click on the arrow next to SelectedValue and bind to
EmployeeBindingSource - ShiftID


That should make the combobox work in both directions (from and to
Employee).

HTH,
Greetings
 
G

Guest

That's it. Thanks.

I guess the key thing I was missing was dragging the whole table out (the
Shift table in my case).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top