473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 3599
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
3
by: dbuchanan | last post by:
These setting mystify me for these reasons. *SelectedItem* - Help says that 'SelectedItem' gets or sets the currently selected item in the combobox. *SelectedValue* - Help says that...
1
by: progressdll | last post by:
I'm trying to change the behaviour of setting the DataSource property of combobox. Here is the behaviour I now see. Setting the DataSource property of combobox to an ArrayList will visual...
1
by: daveg | last post by:
Hi I'm populating a combobox using a dataset and dataadaptor. When the combobox is filled it selects the first value in the database (this is what I want it to do). So I've set the text...
5
by: Rotsey | last post by:
Hi, I have a combobox that when I set the SelectedIndex to -1 it sets to 0. The combobox Items property says there is 20 items in it. Anyone know why this could be please? rotsey
6
by: Smokey Grindle | last post by:
Say I have a combo box with the following simple object Public class MyObject public ID as integer public Name as string public overrides sub ToString() as string return name end sub end...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
5
by: Crazy Cat | last post by:
Hi all, I have combobox that is bound to a custom object collection thusly Dim collection As List(Of StructureType) = StructureType.FindStructureTypes(SharedObjects.StructureTypes,...
7
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.