Help with VB.NET Combobox

G

Guest

Hi,

Is there any way to access the values (not display names)of a combobox ?

For example:

combo1.DataSource = dataset1.tables(0)
combo1.DisplayMember = "Name"
combo1.ValueMember = "ID"

I want to iterate thru the values of the combobox inside my code , but
somehow there is not property for values, i.e. "combo1.Items(1).value "

In ASP.NET, the combobox does have that property but in VB.NET, the combobox
lacks that property.

Does anybody know of any way to iterate thru values in a combobox ?

Thanks,
Hang
 
C

Cor Ligthert [MVP]

Scott,

There is no need to iterate through the combobox, the datasource of that is
much easier to use (in fact your table(0)..

If you tell us what you want to achieve than we can help you probably more
exact because the possibilities to get a value are almost endless with that.

By the way, did you know that there is a better newsgroup for questions like
this.
Microsoft.public.dotnet.languages.vb

Cor
 
G

Guest

Hi Cor,

I set-up a combobox in the Form Load event:

in the Form_Load event
combo1.DataSource = dataset1.tables(0)
combo1.DisplayMember = "Name"
combo1.ValueMember = "ID"

Then I do a search for a record which return an ID .. the ID represents the
value of the combobox's item that needs to be selected.

How do I compare the value returned in my query to the values in the
combobox ?

Thanks,
Hang
 
C

Cor Ligthert [MVP]

Scott one example written in this message so watch typos
in the Form_Load event
combo1.DataSource = dataset1.tables(0).DefaultView
dataset1.tables(0).DefaultView.Sort = "Name"
combo1.DisplayMember = "Name"
combo1.ValueMember = "ID"
combo1.SelectedIdex = dataset1.tables(0).Defaultview.Find("Scott")

Know that in this case the selectedindexchange event is firing.

Cor
 
R

Raymond Maillard

valuetocompare = combo1.selectedvalue


Scott Lam said:
Hi Cor,

I set-up a combobox in the Form Load event:

in the Form_Load event
combo1.DataSource = dataset1.tables(0)
combo1.DisplayMember = "Name"
combo1.ValueMember = "ID"

Then I do a search for a record which return an ID .. the ID represents
the
value of the combobox's item that needs to be selected.

How do I compare the value returned in my query to the values in the
combobox ?

Thanks,
Hang
 
G

Guest

Cor,

Thanks for you help .
It does the trick , the only downside is that I have to keep the dataset
alive and not destroyed it once I populate the combo box.
I wish Microsoft would just add a "values property" to the VB.NET Combobox
like in ASP.NET

Anyways, thank you.

hang
 
C

Cor Ligthert [MVP]

Scott,

Why should you destroy it, keep in mind that there are big differences in
developing for the web and developing winforms, despite some tales seem to
tell.

Cor
 

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