Bound Combo Box, Lookup Table?

J

James

I am used to VB6 but need to develop something in .Net.

I need to create several bound combo-boxes which will use lookup tables to
get their values.

I created a form using the dataform wizard. As part of the setup, I
specified a new dataset, which included the data & lookup tables. I also
specified the relationships when required.

I then added a combo box control to my form, following the instructions from
dynamic help:

I set the datasource for the control to the lookup table.
I set the DisplayMember to the required text column from my lookup table.
I set the ValueMember to the required ID column from my lookup table.

Under DataBindings.SelectedValue I specified my base table, & relevant
column.


This all appears to work, however the problem appears to arise with null
values.

When the form is loaded & the data is fetched, if the source column for the
lookup is null, the combo displays the first entry in the list of the combo
control.
If I select a value, & select the update button (the form was created with
teh standard settings in the wizard), the correct value is inserted into the
underlying table. However, when I navigate to the next record, if it is
null, again the first value in the list is displayed.
Finally, if I attempt to remove a value from the form (i.e. make it null) &
then update, the update will succeed. However the combo will then update &
show the first entry in the list.



I had a look at the code executing with a watch placed on the SelectedValue
property of the combo. It is always correct until, as part of the
UpdateDataSet sub, the DataSet.Merge method is called. At this point the
first value is displayed in the combo.



Any suggestions for a solution?


Cheers,


James
 
J

James Goodman

I have now replicated this with from the Combo box demonstration on msdn
(http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbwlkcreatinglook
uptableondata-boundwindowsform.asp?frame=true&_r=1)


The file can be found here:
http://www.j.goodman.dsl.pipex.com/files/LookupTableExample.zip

This example also requires the Northwind sample db. If you set the value of
CustomerID to Null for a record, & then load the form it demonstrates this
phenomenon. If the modified record is loaded first, the combo will be blank.
However, if the user navigates to the next (or previous) record, & then back
to the record, the combo will show the first entry in the list.
 

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