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

  • Home
  • SEARCH
  • 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 4090524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:14:58+00:00 2026-05-20T19:14:58+00:00

I have a combo box that is bound to a list of model objects.

  • 0

I have a combo box that is bound to a list of model objects. I’ve bound the combo box SelectedItem to a property that is the model type. All of my data binding works beautifully after the window has been loaded. The SelectedItem is set properly and I’m able to save the object directly with the repository.

The problem is when the window first loads I initialize the SelectedItem property and my combobox displays nothing. Before I moved to binding to objects I was binding to a list of strings and that worked just fine on initialization. I know I’m missing something but I can’t figure it out.

Thanks in advance for any guidance you can provide.

(One note about the layout of this page. The combo boxes are actually part of another ItemTemplate that is used in a ListView. The ListView is bound to an observable collection in the main MV. Each item of this observable collection is itself a ModelView. It is that second ModelView that has the SelectedItem property.)

Here is my Model:

    public class DistributionListModel : Notifier, IComparable
    {
    private string m_code;
    private string m_description;

    public string Code
    {
        get { return m_code; }
        set { m_code = value; OnPropertyChanged("Code"); }
    }

    public string Name
    {
        get { return m_description; }
        set { m_description = value; OnPropertyChanged("Name"); }
    }

    #region IComparable Members

    public int CompareTo(object obj)
    {
        DistributionListModel compareObj = obj as DistributionListModel;
        if (compareObj == null)
            return 1;

        return Code.CompareTo(compareObj.Code);
    }

    #endregion
}

Here the pertinent code in my ModelView:

public MailRoutingConfigurationViewModel(int agencyID)
    : base()
{
    m_agencyID = agencyID;
    m_agencyName = DataManager.QueryEngine.GetAgencyName(agencyID);

    IntializeValuesFromConfiguration(DataManager.MailQueryEngine.GetMailRoutingConfiguration(agencyID));

    // reset modified flag
    m_modified = false;
}

private void IntializeValuesFromConfiguration(RecordCheckMailRoutingConfiguration configuration)
{
    SelectedDistributionList = ConfigurationRepository.Instance.GetDistributionListByCode(configuration.DistributionCode);
}

public DistributionListModel SelectedDistributionList
{
    get { return m_selectedDistributionList; }
    set
    {
        m_selectedDistributionList = value;
        m_modified = true;
        OnPropertyChanged("SelectedDistributionList");
    }

}

And finally the pertinent XAML:

<UserControl.Resources>
        <DataTemplate x:Key="DistributionListTemplate">
            <Label Content="{Binding Path=Name}" />
        </DataTemplate>
</UserControl.Resources>
              <ComboBox 
                       ItemsSource="{Binding Source={StaticResource DistributionCodeViewSource}, Mode=OneWay}"
                       ItemTemplate="{StaticResource DistributionListTemplate}"
                                        SelectedItem="{Binding Path=SelectedDistributionList, Mode=TwoWay}"
                        IsSynchronizedWithCurrentItem="False"
                                         />
  • 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-20T19:14:58+00:00Added an answer on May 20, 2026 at 7:14 pm

    @SRM, if I understand correctly your problem is binding your comboBox to a collection of objects rather than a collection of values types ( like string or int- although string is not value type).
    I would suggest add a two more properties on your combobox

    <ComboBox 
      ItemsSource="{Binding Source={StaticResource DistributionCodeViewSource}, 
                            Mode=OneWay}"                        
      ItemTemplate="{StaticResource DistributionListTemplate}"
      SelectedItem="{Binding Path=SelectedDistributionList, Mode=TwoWay}"
      SelectedValuePath="Code"  
      SelectedValue="{Binding SelectedDistributionList.Code }"/>
    

    I am assuming here that DistributionListModel objects are identified by their Code.
    The two properties I added SelectedValuePath and SelectedValue help the combobox identify what properties to use to mark select the ComboBoxItem by the popup control inside the combobox.
    SelectedValuePath is used by the ItemSource and SelectedValue by for the TextBox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox on my form that is bound to a generic list
I have a function that presents the user a combo-box. def select_interface(interfaces) list_box :items
I have a combo box with the following DataTemplate: <DataTemplate x:Key=ComboBoxDataTemplate> <StackPanel> <TextBlock Text={Binding
Setup: I have a combo-box, it's itemsource bound to an ObservableCollection<T> of a custom
I have a ComboBox (Windows Forms) that is bound to a List. It is
I have a ComboBox that has its ItemsSource bound to a static List<CustomSettings> of
I have a combo box inside a list view. And different items (rows) in
Greetings all, I have a list of Types meeting a certain critera that I
I have a combo box that I want to display options based on the
I have a Flex ComboBox that gets populated by a dataprovider all is well...

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.