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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:03:25+00:00 2026-05-24T14:03:25+00:00

I am using WPF and an MVVM pattern. All the comboboxes that are bound

  • 0

I am using WPF and an MVVM pattern. All the comboboxes that are bound to lists work fine, but I have a cascading dropdown that uses a CollectionViewSource for filtering. The filtering works, as does the setter (which while searching for an answer, I saw another person having trouble with), but I am unable to set the initial value. I have tried a few methods, but none seem to affect the selecteditem.

Viewmodel ctor, and Property setter (_ticket.SelectedSubstatus is set in the model constructor):

public TicketViewModel()
    {
        _ticket = new TicketModel();
        SubstatusList = CollectionViewSource.GetDefaultView(GetStatusList());
        SubstatusList.Filter = (x) => { return (int)(x as Substatus).IST_MAIN_STATUS == (int)SelectedStatus.IST_STATUS_ID; };

        SubstatusList.MoveCurrentTo(_ticket.SelectedSubstatus);
        SelectedSubstatus = _ticket.SelectedSubstatus;

        Substatus test = (Substatus)SubstatusList.CurrentItem;

    }

public Substatus SelectedSubstatus
    {
        get { return _ticket.SelectedSubstatus; }
        set
        {
            if (value == _ticket.SelectedSubstatus ||value == null)
                return;

            _ticket.SelectedSubstatus = value;
            _ticket.Issue.IS_SUBSTATUS_ID = value.IST_SUBSTATUS_ID;

            base.OnPropertyChanged("SelectedSubstatus");
        }
    }

and here is the combobox XAML

<ComboBox HorizontalAlignment="Stretch" Margin="15,0,0,0"
                                  Name="comboBox1" VerticalAlignment="Bottom" 
                                  Grid.Column="2" Grid.Row="1" FontSize="12" 
                                  IsSynchronizedWithCurrentItem="True"
                                  ItemsSource="{Binding Path=SubstatusList}" 
                                  SelectedItem="{Binding Path=SelectedSubstatus, Mode=TwoWay}" 
                                  DisplayMemberPath="IST_NAME"/>

The current item from the CollectionViewSource is null just after being set by MoveCurrentTo(), and when checked by test. What am I doing wrong?

  • 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-24T14:03:26+00:00Added an answer on May 24, 2026 at 2:03 pm

    By default, objects are checked if they are equal by reference, not value.

    So if _ticket.SelectedSubstatus does not directly reference an item in SubstatusList, then the SelectedSubstatus will be NULL because you are trying to set the SelectedSubstatus equal to an item that doesn’t exist in the SubstatusList

    To get around this, overwrite the .Equals() method of Substatus to return true if an object’s data is the same. For example,

    public override bool Equals(object obj)
    {
          if (obj == null) return false;
          if (obj.GetType() != this.GetType()) return false;
    
          return this.Id == ((SubStatus)obj).Id;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF app that is using the MVVM pattern. Hooking up buttons
In a WPF app that I'm writing using the MVVM pattern, I have a
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I am coding a WPF application using MVVM pattern. I don't need to have
I'm creating a WPF application using the MVVM design pattern that consists of a
I am using WPF MVVM Pattern. I have 2 ListBoxes and a DataGrid in
I'm using the MVVM pattern in my first WPF app and have a problem
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I am developing an application in WPF using the MVVM pattern. If I have
I am building a WPF app that is based on the MVVM pattern (using

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.