• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Update object values in ComboBox

Hi All,
I have, say, a class called Person with two properties: ID and Name, each object can add, update and delete itself to/from a database.  So if I add a bunch of these Person objects to a DropDownList box (in some kind of loop), that has its Value member set to ID and Display member set to Name - all works fine.  

I also have a textbox control that I use to enter either new or update the values for the Name property of each Person object.  All works fine except for one annoying thing when updating.  You can type the new Name value in the textbox and save it no problem, but how can I get the actual value in the DropDownList to also change its Name value without reloading the entire table?

Any ideas are much appreciated!
John.  
0
siskinds
Asked:
siskinds
1 Solution
 
anarki_jimbelCommented:
I think there are at least two options.

One is to store all objects in some kind of collection, and make a collection a datrasource for the dropdown list. In this case any aupadets to the content of the collection would be reflected automatically in the list.

Another option is to find the element to be changed "manually" in the dropdown list and edit it's displayed value.

Second one is easier to implement (if names are not unique - it might be a problem...).
First one can be more tricky.
0
 
JimBrandleyCommented:
If the textbox is populated by yourComboBox.Items(yourComboBox.SelectedIndex).Name before the edit,
you can:
yourComboBox.Items(yourComboBox.SelectedIndex).Name = newName;

Jim
0
 
siskindsAuthor Commented:
Thanks for your input guys.

Jim, you were close.  I had no access to the "Name", nor Text property of the Person object this way so simply replaced the currently selected object with the one I just modified and volia!
myComboBox.Items[myComboBox.SelectedIndex] = newModifiedObject.

Thanks
John.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now