Assigning datasource to combo box

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am using below code to fill the drop down list of a combo box from a table
in the dataset;

Dim dv As New DataView(ds.Companies)
Me.txtParent.DataSource = dv
Me.txtParent.DataMember = "Company"
dv.Dispose()
dv = Nothing

Unfortunately no data turns up in combo box. What am I doing wrong?

Thanks

Regards
 
John said:
I am using below code to fill the drop down list of a combo box from a
table in the dataset;

Dim dv As New DataView(ds.Companies)
Me.txtParent.DataSource = dv
Me.txtParent.DataMember = "Company"
dv.Dispose()
dv = Nothing

Unfortunately no data turns up in combo box. What am I doing wrong?

Remove the last two lines. You must not destroy the data source as long as
the control depends on it. In addition, setting local variables to
'Nothing' is (with very few exception) not the best style.
 
Hi

Thanks. No luck I am afraid. I have tried all this;

Dim dv As New DataView(ds.Clients)

1. Me.txtParent.DataSource = "dv.company"

2. Me.txtParent.DataSource = dv
Me.txtParent.DataMember = "company"

3. Me.txtParent.DataSource = ds.Clients
Me.txtParent.DataMember = "company"

Any ideas? I have tested ds.Clients.Count and it returns more than zero so
there are records in the dataset.

Thanks

Regards
 
John,

Are you sure you have the right control. I see seldom people call a combobox
txt that is mostly (forever) used for a textbox.

You have to set the displaymember in the way you did it as in 2 and 3.
However, normally the valuemember is set as well.

Cor
 
You need to set the display member and value member. They can be the same
thing. They must be what field in the dataset you want to use.

Me.txtParent.DataSource = ds.Clients
Me.txtParent.DisplayMember = "CompanyName"
Me.txtParent.ValueMember = "CompanyID"

RobinS.
GoldMail, Inc.
------------------------------------
John said:
Hi

Thanks. No luck I am afraid. I have tried all this;

Dim dv As New DataView(ds.Clients)

1. Me.txtParent.DataSource = "dv.company"

2. Me.txtParent.DataSource = dv
Me.txtParent.DataMember = "company"

3. Me.txtParent.DataSource = ds.Clients
Me.txtParent.DataMember = "company"

Any ideas? I have tested ds.Clients.Count and it returns more than zero so
there are records in the dataset.

Thanks

Regards
 

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

Back
Top