Help with combobox databinding and Items (collection)

R

Rick Shaw

Hi. I've struggling with the combobox databinding in C#. What I was trying
to do was:

- Hard code the items in the combobox's Items (collection) property. (ie.
'Mon', 'Tue', 'Wed', 'Thu', 'Fri')
- Then databind the combobox to a table in the dataset.

Since the table (in the dataset) contains just a tiny subset (1 to 5
records) of what is in the database, it might contain, for example,
the values 'Mon' and 'Thu' only.

Right now, when I databind the control to the dataset, I think, it clears
the hard coded items in the control and replace it with what in the table.

Can someone help.

Thanks,

Rick..
 
M

Marc Gravell

When you say databind here, I assume you mean .DataSource, not
..Bindings? i.e. you are binding the list and not the selected items? In
which case this is the expected behaviour - it only allows one data
source: *either* the internal list, *or* an external datasource.

You need to either add the extra items to the dataset, or add the
dataset items to the .Items, or add both sets to a List<T> and bind to
that instead. Or live with it.

Marc
 

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