StrataFrame Forum

Setting the combobox selection based on value instead of index

http://forum.strataframe.net/Topic3329.aspx

By Andria Jensen - 10/5/2006

I'm using the Inherited UI ComboBoxEdit and I want to save the selection of this and a bunch of other combos on a form and then be able to restore them when I come back to that same form.  The ValueMember and DisplayValue properties may not be the same and for other reasons I need to save out the SelectedValue instead of the SelectedIndex.  I can save it out just fine using the SelectedValue property.  Is there a way to just set a property on the combo box and have it select the corresponding item in the list when I go to restore my selections?  I tried setting SelectedValue to the value which was saved out, but this does not work.  I was going to just right a little method to search through the Items collection and set SelectedIndex based on which item matches the saved SelectedValue.  I just wanted to make sure there wasn't an easier way before I implement unnecessary code.  Thanks Smile
By StrataFrame Team - 10/5/2006

You should be able to set the SelectedValue property directly, however, there was a logic error in the way that the indexor for the items collection was being called... if the type of the selected value was an integer, then the wrong overload was being called and it would not have given you the correct functionality.  I fixed it and we're going to post an update later today, probably within the next couple of hours.  I'll let you know.
By Andria Jensen - 10/5/2006

Awesome, thanks!  Yes, the one I was having problems with specifically was using an  integer value as the ValueMember.  That's probably where my problem is coming from.  Let me know when I can download the update.  Thanks again.