471,073 Members | 1,130 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Setting a ComboBox's Value

Hi,

I am having a problem setting a combobox value in code on form load using
comboBox.SelectedValue method. The code below when debugging show the
combobox equal to an undefined value. The value I am trying to set is
present the items collection. I also have tried using .SelectedItem method
and I get an object reference error. Any ideas?

comboBox.SelectedValue = comboBoxValue;

Thanks
Nov 16 '05 #1
2 3481
Fred,

Have you used DataBinding with Display,Value pair to add items to the
ComboBox, in that case use SelectedValue property, otherwise use
SelectedIndex property to select a default value during load.

Hope it helps.

this.cboCollect.Items.Add("abc");

this.cboCollect.Items.Add("e");

this.cboCollect.Items.Add("g");

this.cboCollect.Items.Add("h");

cboCollect.SelectedIndex = 3;
Thanks,
Vijai

"Fred" <fr**@email.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Hi,

I am having a problem setting a combobox value in code on form load using
comboBox.SelectedValue method. The code below when debugging show the
combobox equal to an undefined value. The value I am trying to set is
present the items collection. I also have tried using .SelectedItem method and I get an object reference error. Any ideas?

comboBox.SelectedValue = comboBoxValue;

Thanks

Nov 16 '05 #2
Thanks, my problem is neither of those methods work!
"vijai thoppae" <vi******@hotmail.com> wrote in message
news:OY*************@TK2MSFTNGP12.phx.gbl...
Fred,

Have you used DataBinding with Display,Value pair to add items to the
ComboBox, in that case use SelectedValue property, otherwise use
SelectedIndex property to select a default value during load.

Hope it helps.

this.cboCollect.Items.Add("abc");

this.cboCollect.Items.Add("e");

this.cboCollect.Items.Add("g");

this.cboCollect.Items.Add("h");

cboCollect.SelectedIndex = 3;
Thanks,
Vijai

"Fred" <fr**@email.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Hi,

I am having a problem setting a combobox value in code on form load using comboBox.SelectedValue method. The code below when debugging show the
combobox equal to an undefined value. The value I am trying to set is
present the items collection. I also have tried using .SelectedItem

method
and I get an object reference error. Any ideas?

comboBox.SelectedValue = comboBoxValue;

Thanks


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rotsey | last post: by
7 posts views Thread by Brad Pears | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.