Home All Groups Group Topic Archive Search About

how to use table in a dataset as data source for combobox?

Author
5 Dec 2006 10:16 PM
Rich
Hello,

I want to use a column in a table that is contained in a dataset (populated
by a dataAdapter) as the datasource for a combobox.  I can get as far as
populating the table with the dataAdapater.  But have a problem adding this
as a data source to the combobox:

combo1.DataSource = ds.Tables("tlb1").columns(0)

The error message that I get is this:  Complex Databinding accepts as a data
source either an IList or an IListSource.  How can I use the column in this
table as the data source for combo1?

Thanks,
Rich

Author
5 Dec 2006 10:21 PM
Rich
I figured it out

combo1.DataSource = ds.Table("tbl1")
combo1.DisplayMember = "column1"

this will display the contents of a column called "column1"

Show quoteHide quote
"Rich" wrote:

> Hello,
>
> I want to use a column in a table that is contained in a dataset (populated
> by a dataAdapter) as the datasource for a combobox.  I can get as far as
> populating the table with the dataAdapater.  But have a problem adding this
> as a data source to the combobox:
>
> combo1.DataSource = ds.Tables("tlb1").columns(0)
>
> The error message that I get is this:  Complex Databinding accepts as a data
> source either an IList or an IListSource.  How can I use the column in this
> table as the data source for combo1?
>
> Thanks,
> Rich
Author
5 Dec 2006 10:32 PM
Rad [Visual C# MVP]
On Tue, 5 Dec 2006 14:16:00 -0800, Rich wrote:

Show quoteHide quote
> Hello,
>
> I want to use a column in a table that is contained in a dataset (populated
> by a dataAdapter) as the datasource for a combobox.  I can get as far as
> populating the table with the dataAdapater.  But have a problem adding this
> as a data source to the combobox:
>
> combo1.DataSource = ds.Tables("tlb1").columns(0)
>
> The error message that I get is this:  Complex Databinding accepts as a data
> source either an IList or an IListSource.  How can I use the column in this
> table as the data source for combo1?
>
> Thanks,
> Rich

Rich, try this:

1) Change the data source to be the combo box to be the actual table

combo1.DataSource = ds.Tables("tlb1")

2) Change the DisplayMember of the column to the name of your column

combo1.DataSource = "ColumnName"

Author
5 Dec 2006 10:45 PM
Rich
Thanks.  Yes I see the way now. 

Question:  what option should I select for the autocompleteSource property?

My list is pretty long, 35,000 unique ID's.  I select ListItems, but it
takes the combobox a while to load.  I also am using Application.DoEvents. 
Any suggestions appreciated how I could speed up the loading of the
datasource to the combobox.  The dataset loads in a second or two.  But the
combobox takes its time.

Show quoteHide quote
"Rad [Visual C# MVP]" wrote:

> On Tue, 5 Dec 2006 14:16:00 -0800, Rich wrote:
>
> > Hello,
> >
> > I want to use a column in a table that is contained in a dataset (populated
> > by a dataAdapter) as the datasource for a combobox.  I can get as far as
> > populating the table with the dataAdapater.  But have a problem adding this
> > as a data source to the combobox:
> >
> > combo1.DataSource = ds.Tables("tlb1").columns(0)
> >
> > The error message that I get is this:  Complex Databinding accepts as a data
> > source either an IList or an IListSource.  How can I use the column in this
> > table as the data source for combo1?
> >
> > Thanks,
> > Rich
>
> Rich, try this:
>
> 1) Change the data source to be the combo box to be the actual table
>
> combo1.DataSource = ds.Tables("tlb1")
>
> 2) Change the DisplayMember of the column to the name of your column
>
> combo1.DataSource = "ColumnName"
>
> --
> Bits.Bytes
> http://bytes.thinkersroom.com
>
Author
6 Dec 2006 1:00 AM
Martin Milan
> My list is pretty long, 35,000 unique ID's.  I select ListItems, but
> it takes the combobox a while to load.  I also am using
> Application.DoEvents.  Any suggestions appreciated how I could speed
> up the loading of the datasource to the combobox.  The dataset loads
> in a second or two.  But the combobox takes its time.

I would ask yourself the question "Is a combo box the correct control
from which to ask the user to select one of 35000 ids?"
Author
6 Dec 2006 5:19 AM
Rad [Visual C# MVP]
On Tue, 5 Dec 2006 14:45:01 -0800, Rich wrote:

> Question:  what option should I select for the autocompleteSource property?
>
> My list is pretty long, 35,000 unique ID's.  I select ListItems, but it
> takes the combobox a while to load.  I also am using Application.DoEvents. 
> Any suggestions appreciated how I could speed up the loading of the
> datasource to the combobox.  The dataset loads in a second or two.  But the
> combobox takes its time.

Rich,

My GOODNESS!!! 35,000 is a lot of items. Picture your user who has to
scroll down to the last item!

Is there any way to filter the data that goes into the combo box? That is
not very user friendly!


Author
6 Dec 2006 5:37 AM
Cor Ligthert [MVP]
Rich,

Beside the DisplayMember you have the ValueMember, have a look at it,

(by the way 35000 is to much for a combo).

I would create an extra table and than use that to populate another combobox
that is the base for this table. (using dataviews)

Cor

Show quoteHide quote
"Rich" <R***@discussions.microsoft.com> schreef in bericht
news:7C3D6DFB-3C0B-4B40-91A4-EBF6C7401B71@microsoft.com...
> Thanks.  Yes I see the way now.
>
> Question:  what option should I select for the autocompleteSource
> property?
>
> My list is pretty long, 35,000 unique ID's.  I select ListItems, but it
> takes the combobox a while to load.  I also am using Application.DoEvents.
> Any suggestions appreciated how I could speed up the loading of the
> datasource to the combobox.  The dataset loads in a second or two.  But
> the
> combobox takes its time.
>
> "Rad [Visual C# MVP]" wrote:
>
>> On Tue, 5 Dec 2006 14:16:00 -0800, Rich wrote:
>>
>> > Hello,
>> >
>> > I want to use a column in a table that is contained in a dataset
>> > (populated
>> > by a dataAdapter) as the datasource for a combobox.  I can get as far
>> > as
>> > populating the table with the dataAdapater.  But have a problem adding
>> > this
>> > as a data source to the combobox:
>> >
>> > combo1.DataSource = ds.Tables("tlb1").columns(0)
>> >
>> > The error message that I get is this:  Complex Databinding accepts as a
>> > data
>> > source either an IList or an IListSource.  How can I use the column in
>> > this
>> > table as the data source for combo1?
>> >
>> > Thanks,
>> > Rich
>>
>> Rich, try this:
>>
>> 1) Change the data source to be the combo box to be the actual table
>>
>> combo1.DataSource = ds.Tables("tlb1")
>>
>> 2) Change the DisplayMember of the column to the name of your column
>>
>> combo1.DataSource = "ColumnName"
>>
>> --
>> Bits.Bytes
>> http://bytes.thinkersroom.com
>>