Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:16:56+00:00 2026-05-31T14:16:56+00:00

I’m not quite sure how to deal with this problem. I’m using a bunch

  • 0

I’m not quite sure how to deal with this problem. I’m using a bunch of comboboxes with dropdown lists of values we allow the user to set a property too. (i.e. Currencies = “USD, CAD, EUR”).

Every now and then, when we load data, we’ll find the currency is something not in our list, like “AUD”. In this case, we still want the combobox to display the loaded value, and the current selected Currency should remain “AUD” unless the user chooses to change it, in which case their only options will still be “USD, CAD, EUR”.

My problem is that as soon as the control becomes visible, the ComboBox is calling the setter on my SelectedCurrency property and setting it to null, presumably because the current value “AUD” isn’t in it’s list. How can I disable this behaviour without making it possible for the user to type whatever they want into the Currency field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:16:57+00:00Added an answer on May 31, 2026 at 2:16 pm

    This seems to be a reasonably common problem. Imagine you have a lookup list in the database, maybe a list of employees. The employee table has a ‘works here’ flag. Another table references the employee lookup list. When a person leaves the company, you want your views to show the name of the old employee, but not allow the old employee to be assigned in future.

    Here’s my solution to the similar currency problem:

    Xaml

    <Page.DataContext>
        <Samples:ComboBoxWithObsoleteItemsViewModel/>
    </Page.DataContext>
    <Grid>
        <ComboBox Height="23" ItemsSource="{Binding Items}" 
                  SelectedItem="{Binding SelectedItem}"/>
    </Grid>
    

    C#

    // ViewModelBase and Set() are from MVVM Light Toolkit
    public class ComboBoxWithObsoleteItemsViewModel : ViewModelBase
    {
        private readonly string _originalCurrency;
        private ObservableCollection<string> _items;
        private readonly bool _removeOriginalWhenNotSelected;
        private string _selectedItem;
    
        public ComboBoxWithObsoleteItemsViewModel()
        {
            // This value might be passed in to the VM as a parameter
            // or obtained from a data service
            _originalCurrency = "AUD";
    
            // This list is hard-coded or obtained from your data service
            var collection = new ObservableCollection<string> {"USD", "CAD", "EUR"};
    
            // If the value to display isn't in the list, then add it
            if (!collection.Contains(_originalCurrency))
            {
                // Record the fact that we may need to remove this
                // value from the list later.
                _removeOriginalWhenNotSelected = true;
                collection.Add(_originalCurrency);
            }
    
            Items = collection;
    
            SelectedItem = _originalCurrency;
        }
    
        public string SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                // Remove the original value from the list if necessary
                if(_removeOriginalWhenNotSelected && value != _originalCurrency)
                {
                    Items.Remove(_originalCurrency);
                }
    
                Set(()=>SelectedItem, ref _selectedItem, value);
            }
        }
    
        public ObservableCollection<string> Items
        {
            get { return _items; }
            private set { Set(()=>Items, ref _items, value); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.