Discussion:
Help with VB.NET Combobox
(too old to reply)
Scott Lam
2006-12-21 05:27:01 UTC
Permalink
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
Cor Ligthert [MVP]
2006-12-21 06:25:27 UTC
Permalink
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
Post by Scott Lam
Hi,
Is there any way to access the values (not display names)of a combobox ?
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
Scott Lam
2006-12-21 06:55:00 UTC
Permalink
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
Post by 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
Post by Scott Lam
Hi,
Is there any way to access the values (not display names)of a combobox ?
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
Cor Ligthert [MVP]
2006-12-21 19:20:15 UTC
Permalink
Scott one example written in this message so watch typos
Post by Scott Lam
in the Form_Load event
combo1.DataSource = dataset1.tables(0).DefaultView
dataset1.tables(0).DefaultView.Sort = "Name"
Post by Scott Lam
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
Scott Lam
2006-12-22 00:18:01 UTC
Permalink
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
Post by Cor Ligthert [MVP]
Scott one example written in this message so watch typos
Post by Scott Lam
in the Form_Load event
combo1.DataSource = dataset1.tables(0).DefaultView
dataset1.tables(0).DefaultView.Sort = "Name"
Post by Scott Lam
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
Cor Ligthert [MVP]
2006-12-22 05:07:22 UTC
Permalink
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
Post by Scott Lam
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
Post by Cor Ligthert [MVP]
Scott one example written in this message so watch typos
Post by Scott Lam
in the Form_Load event
combo1.DataSource = dataset1.tables(0).DefaultView
dataset1.tables(0).DefaultView.Sort = "Name"
Post by Scott Lam
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
Raymond Maillard
2006-12-21 21:18:07 UTC
Permalink
valuetocompare = combo1.selectedvalue
Post by Scott Lam
Hi Cor,
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
Post by 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
Post by Scott Lam
Hi,
Is there any way to access the values (not display names)of a combobox ?
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
Loading...