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 7896689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:57:34+00:00 2026-06-03T07:57:34+00:00

Suppose I have two comboboxes. One for the lower-value and one for the upper

  • 0

Suppose I have two comboboxes. One for the lower-value and one for the upper value. The user must select both values. To make it comfortable for her, I’d like to prevent the error (lower>upper) by limiting the values in the upper-value-combobox.

<example>

Here an example. (In the example, I use integers – my real world problem has different objects.)

  1. The user has the choice within the range [1..5]:

    lower: [1, 2, 3, 4, 5]  --> no lower-value selected
    upper: [1, 2, 3, 4, 5]  --> no upper-value selected
    
  2. If she selects 3 as the lower value, I’d like the upper-checkbox to provide only the values [3..5]. This works fine by changing the databound ObservableCollection<MyObj> of the upper-combobox.

    lower: [1, 2, __3__, 4, 5]  --> User has selected '3'
    upper: [3, 4, 5]            --> after that, only values within the range [3..5] are available.
    
  3. User selects 4 as the upper-value

    lower: [1, 2, __3__, 4, 5]  --> User has selected '3'
    upper: [3, __4__, 5]        --> User has selected '4'
    
  4. User changes his mind and selects 2 as the lower value

    lower: [1, __2__, 3, 4, 5]  --> User has selected '2'
    upper: [2, 3, __4__, 5]     --> '4' should be kept selected
    

</example>

In the windows-forms world, I would have created a user-control and control the event-handling myself. In fact, I would turn off the handling of SelectedIndexChanged event of the upper-combobox, adjust it’s underlying list, set the appropriate index and turn the eventhandling back on again.

I’ve encountered a weird problem in the forth step. I found no way to keep the selected value while changing the underlying collection.

  • What’s the mvvm-way of dealing with concerns like these? Or isn’t the mvvm-pattern the right medicine for my scenario?
  • Is this the right place for a usercontrol, where I have full control over the event-handling?
  • Is Expression-Blend really built using the mvvm-pattern? 😉
  • 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-06-03T07:57:36+00:00Added an answer on June 3, 2026 at 7:57 am

    instead of create a new upper collection everytime, why not simply use a ICollectionView.Filter? so you can hold your selected item.

    EDIT: fast and dirty example 😉

    public class MyCbo
    {
        private int _selectedInt;
        public int SelectedInt
        {
            get { return _selectedInt; }
            set { _selectedInt = value; 
            this.view.Refresh();}
        }
    
        public List<int> MyFirst { get; set; }
        public List<int> MySecond { get; set; }
    
        private ICollectionView view;
    
        public MyCbo()
        {
            this.MyFirst = new List<int>() {1, 2, 3, 4, 5};
            this.MySecond = new List<int>() { 1, 2, 3, 4, 5 };
    
            this.view = CollectionViewSource.GetDefaultView(this.MySecond);
            this.view.Filter = Myfilter;
        }
    
        private bool Myfilter(object obj)
        {
            var item = Convert.ToInt32(obj);
    
            var upper = this.SelectedInt;
    
            if (item < upper)
                return false;
    
            return true;
        }
    }
    

    usercontrol

    public partial class Comboxtwo : UserControl
    {
        private MyCbo data;
        public Comboxtwo()
        {
            this.data = new MyCbo();
            InitializeComponent();
            this.DataContext = data;
        }
    }
    

    xaml

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition  />
        </Grid.ColumnDefinitions>
        <ComboBox Grid.Column="0" ItemsSource="{Binding MyFirst}" SelectedItem="{Binding SelectedInt, Mode=OneWayToSource}" Height="30"/>
        <ComboBox Grid.Column="1" ItemsSource="{Binding MySecond}" Height="30" />
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two entities: User and UserGroup . They have a one-to-many relationship
Suppose you have two models, User and City, joined by a third model CityPermission:
Suppose you have two seperate ASP.NET Web Application projects that both need to use
Suppose I have two classes that both contain a static variable, XmlTag. The second
Suppose I have two tables that are linked (one has a foreign key to
Suppose I have two fingers touching iPhone's screen but just one is moving. TouchesMoved
Suppose I have two classes (one a parent and one a subclass). How do
Suppose I have two scripts. The first one puts (with mv command) some files
Suppose I have two text files. The first one, called reference.txt has the following
Suppose you have two datetime values, date_a and date_b What expression evaluates to true

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.