Dataset binding to comboboxes - As many items as records??

D

Derek

Hi All,

I have been having a hard time figuring how to approach a problem and
was hoping I might be able to get some assistance. Here is my situation.

I have a dataset that is based on a table in my SQL server database. I
am using Databinding to bind the dataset to a series of controls on my
form. A few of these controls are comboboxes. One of the comboboxes is
bound the the field in the dataset that is my primary key (it's called
ID). This works well for me because I can scroll through the combobox
and select whichever record I want to deal with and all the controls are
updated to that record when I select it. The problem however, resides
with another combobox which is bound to a field in the database that can
only have two (2) possible choices, Yes or No. I was expecting that this
combobox would only consist of two possible choices however I am finding
that there are as many "items" in the combobox as there are records in
the database. Granted there are only two possible "values" (Yes or No)
but they are repeated throughout the combobox. Any idea what I am doing
wrong? Has anyone seen this before? Thanks in advance for any
assistance!

- Derek
 
M

Miha Markic

Hi Derek,

Derek said:
Hi All,

I have been having a hard time figuring how to approach a problem and
was hoping I might be able to get some assistance. Here is my situation.

I have a dataset that is based on a table in my SQL server database. I
am using Databinding to bind the dataset to a series of controls on my
form. A few of these controls are comboboxes. One of the comboboxes is
bound the the field in the dataset that is my primary key (it's called
ID). This works well for me because I can scroll through the combobox
and select whichever record I want to deal with and all the controls are
updated to that record when I select it. The problem however, resides
with another combobox which is bound to a field in the database that can
only have two (2) possible choices, Yes or No. I was expecting that this
combobox would only consist of two possible choices however I am finding
that there are as many "items" in the combobox as there are records in
the database. Granted there are only two possible "values" (Yes or No)
but they are repeated throughout the combobox. Any idea what I am doing
wrong? Has anyone seen this before? Thanks in advance for any
assistance!

You are talking about lookups now.
You should fill combobox with all possible values (or bind its DataSource
property to a table *holding* possible values) and set Display/ValueMember
properties accordingly.
You should bind its SelectedValue to your table.
 
D

Derek

Thanks for the response Miha,

I am not sure if I follow all of what you are saying. I think perhaps
I was not that clear. Let me explain further.

I have one combobox that I use as a lookup. This contains all the
unique ID's of the records in my table. When I choose a selection in
this combobox all the bound fields on the form change to reflect the
data in the selected record.
I also have another combobox. This one is NOT a lookup. It contains
just two possible fields, YES or NO. I currently have this combobox
bound to the field (column) that is corresponds to in the table that is
bound. I was expecting that this "Yes/No" combobox would reflect the
data in the record selected by the "Lookup" combobox. And it does do
this, however it does it by populating the combobox with one entry for
each record in the database. For example..

Lookup Combobox:
--------------------
1
2
3
4
5
6
7
8
..
..
2000

Yes/No Combobox: (2000 entries)
--------------------
Yes
Yes
No
Yes
Yes
Yes
No
Yes
..
..
No

What I was expecting was this...

Yes/No Combobox (2 entries)
------------------------
Yes
No

If I bind the selectedValue of the Combobox to the dataset then I end
up with 2000 entries rather than 2. Perhaps I am missing something.

- Derek
 

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