473,385 Members | 1,766 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,385 software developers and data experts.

Setting SelectedItem of ComboBox programatically not working

Hi all,

I have combobox that is bound to a custom object collection thusly

Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)

DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"

The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.

When I set the SelectedItem of the ComboBox programatically to a
StructureType object the selecteditem never changes.

Suspecting that the SelectedItem is not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.

When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.

Has anyone seen this before, or am I missing something about
SelectedItem?

PLEASE HELP

Thanks
Nov 28 '07 #1
5 5680
On Nov 28, 2:37 pm, Crazy Cat <danbr...@hotmail.comwrote:
Hi all,

I have combobox that is bound to a custom object collection thusly

Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)

DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"

The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.

When I set the SelectedItem of the ComboBox programatically to a
StructureType object the selecteditem never changes.

Suspecting that the SelectedItem is not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.

When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.

Has anyone seen this before, or am I missing something about
SelectedItem?

PLEASE HELP

Thanks
Is it the same actual object or is it an object with the same data?

--
Tom Shelton
Nov 29 '07 #2
Hi,

I thought that I had seen this more and that it is because are using the
SelectedItem however not the itemarray, why don't you use the itemarray for
this instead of a datasource. For a datasource you can use the
selectedindex. The combobox is combining working with datasources however
has as well as combination an itemarray in it. It is very much working
seperated from each other.

Cor

"Crazy Cat" <da******@hotmail.comschreef in bericht
news:3c**********************************@d21g2000 prf.googlegroups.com...
Hi all,

I have combobox that is bound to a custom object collection thusly

Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)

DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"

The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.

When I set the SelectedItem of the ComboBox programatically to a
StructureType object the selecteditem never changes.

Suspecting that the SelectedItem is not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.

When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.

Has anyone seen this before, or am I missing something about
SelectedItem?

PLEASE HELP

Thanks

Nov 29 '07 #3
On Nov 28, 7:35 pm, Tom Shelton <tom_shel...@comcast.netwrote:
On Nov 28, 2:37 pm, Crazy Cat <danbr...@hotmail.comwrote:
Hi all,
I have combobox that is bound to a custom object collection thusly
Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)
DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"
The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.
When I set theSelectedItemof the ComboBox programatically to a
StructureType object theselecteditemnever changes.
Suspecting that theSelectedItemis not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.
When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.
Has anyone seen this before, or am I missing something about
SelectedItem?
PLEASE HELP
Thanks

Is it the same actual object or is it an object with the same data?

--
Tom Shelton
Yes, Tom it is the same object. I get both the datasource and the item
I am attemping to set to the SelectedItem from a much larger
collection (using different methods but still it is run against the
same collection).

I ended up using the SelectedValue property. Thanks much.
Nov 29 '07 #4
On Nov 29, 6:54 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Hi,

I thought that I had seen this more and that it is because are using theSelectedItemhowever not the itemarray, why don't you use the itemarray for
this instead of a datasource. For a datasource you can use the
selectedindex. The combobox is combining working with datasources however
has as well as combination an itemarray in it. It is very much working
seperated from each other.
Hi Cor,

I ended up using the SelectedValue instead of the SelectedItem.

Thanks,

>
Cor

"Crazy Cat" <danbr...@hotmail.comschreef in berichtnews:3c**********************************@d 21g2000prf.googlegroups.com...
Hi all,
I have combobox that is bound to a custom object collection thusly
Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)
DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"
The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.
When I set theSelectedItemof the ComboBox programatically to a
StructureType object theselecteditemnever changes.
Suspecting that theSelectedItemis not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.
When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.
Has anyone seen this before, or am I missing something about
SelectedItem?
PLEASE HELP
Thanks
Nov 29 '07 #5
On Nov 29, 1:47 pm, Crazy Cat <danbr...@hotmail.comwrote:
On Nov 28, 7:35 pm, Tom Shelton <tom_shel...@comcast.netwrote:


On Nov 28, 2:37 pm, Crazy Cat <danbr...@hotmail.comwrote:
Hi all,
I have combobox that is bound to a custom object collection thusly
Dim collection As List(Of StructureType) =
StructureType.FindStructureTypes(SharedObjects.Str uctureTypes,
DropDownListStructure.SelectedValue, DropDownListType.SelectedValue)
DropDownListSubType.DataSource = collection
DropDownListSubType.DisplayMember = "StructureName"
The method FindStructureTypes is a shared method that returns a list
of StructureType objects filtered by the value in another combobox.
When I set theSelectedItemof the ComboBox programatically to a
StructureType object theselecteditemnever changes.
Suspecting that theSelectedItemis not found in the combobox's
datasource I put in a piece of code to print the index of the object
in the collection using List(Of StructureType).IndexOf. As suspected I
get a -1.
When I run this code in debug and look at the collection (15 objects
in all) in QuickWatch I can see that the object is in the collection.
These objects are retrieved from a database and have a unique ID
property. The StructureType object that I am setting in the combobx
comes from the same list as the datasource using a method that
retrieves just one item by ID.
Has anyone seen this before, or am I missing something about
>SelectedItem?
PLEASE HELP
Thanks
Is it the same actual object or is it an object with the same data?
--
Tom Shelton

Yes, Tom it is the same object. I get both the datasource and the item
I am attemping to set to the SelectedItem from a much larger
collection (using different methods but still it is run against the
same collection).

I ended up using the SelectedValue property. Thanks much.- Hide quoted text -

- Show quoted text -
Glad you found a solution.

--
Tom Shelton
Nov 29 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fred | last post by:
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...
1
by: gordon | last post by:
Hi I have a combo box that my application uses to select an item for a regression function. I would like to convert the selected item to a string value and use this value later in my code. ...
8
by: VB User | last post by:
I would like the text property of combo box to read the first item of the list on form load. I have a set of four items in the collection. How do I do it? Thanks
7
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
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: JP | last post by:
I have C# ASP.NET VS 2005 combo box set to perform an auto post back when the user changes the index protected void dropSSNEdit_SelectedIndexChanged(object sender, EventArgs e) { txtSSN.Text...
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...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.