|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting SelectedItem of ComboBox programatically not workingI have combobox that is bound to a custom object collection thusly Dim collection As List(Of StructureType) = StructureType.FindStructureTypes(SharedObjects.StructureTypes, 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 On Nov 28, 2:37 pm, Crazy Cat <danbr***@hotmail.com> wrote:
Show quote > Hi all, Is it the same actual object or is it an object with the same data?> > I have combobox that is bound to a custom object collection thusly > > Dim collection As List(Of StructureType) = > StructureType.FindStructureTypes(SharedObjects.StructureTypes, > 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 -- Tom Shelton On Nov 28, 7:35 pm, Tom Shelton <tom_shel***@comcast.net> wrote:
Show quote > On Nov 28, 2:37 pm, Crazy Cat <danbr***@hotmail.com> wrote: Yes, Tom it is the same object. I get both the datasource and the item> > > > > Hi all, > > > I have combobox that is bound to a custom object collection thusly > > > Dim collection As List(Of StructureType) = > > StructureType.FindStructureTypes(SharedObjects.StructureTypes, > > 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 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. On Nov 29, 1:47 pm, Crazy Cat <danbr***@hotmail.com> wrote:
Show quote > On Nov 28, 7:35 pm, Tom Shelton <tom_shel***@comcast.net> wrote: Glad you found a solution.> > > > > > > On Nov 28, 2:37 pm, Crazy Cat <danbr***@hotmail.com> wrote: > > > > Hi all, > > > > I have combobox that is bound to a custom object collection thusly > > > > Dim collection As List(Of StructureType) = > > > StructureType.FindStructureTypes(SharedObjects.StructureTypes, > > > 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 - -- Tom Shelton 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 Show quote "Crazy Cat" <danbr***@hotmail.com> schreef in bericht news:3ca94293-5cab-42fa-a0a5-bbfc5df363d5@d21g2000prf.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.StructureTypes, > 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 On Nov 29, 6:54 am, "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> Hi Cor,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. I ended up using the SelectedValue instead of the SelectedItem. Thanks, Show quote > > Cor > > "Crazy Cat" <danbr***@hotmail.com> schreef in berichtnews:3ca94293-5cab-42fa-a0a5-bbfc5df36***@d21g2000prf.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.StructureTypes, > > 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 |
|||||||||||||||||||||||