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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:51:48+00:00 2026-05-22T15:51:48+00:00

In XAML I have a combobox defined as: <ComboBox x:Name=UsernameComboBox ItemsSource={Binding Users} DisplayMemberPath=Username SelectedItem={Binding

  • 0

In XAML I have a combobox defined as:

<ComboBox x:Name="UsernameComboBox" 
          ItemsSource="{Binding Users}" 
          DisplayMemberPath="Username" 
          SelectedItem="{Binding Path=SelectedName, Mode=TwoWay}"/>

Right now, it doesn’t show any default selected item.

I fill the combo box with a list:

public List<User> Users
{
    get
    {
        return _userRepository.RetrieveUsers();
    }
}

public List<User> RetrieveUsers()
{
    _users = (from Users in _db.Users select Users).ToList();

    return _users;
}

The proper Users being the ItemSource for the combobox. then in the XAML I defined SelectedItem and bound it to a property called Selected name.

In code this looks like:

    private User _selectedName;
    public User SelectedName
    {
        get
        {
            return _selectedName;
        }
        set 
        {
            if (_selectedName == value) return;
            _selectedName = value;
            OnPropertyChanged("SelectedName");
        }
    }

How can I get my combobox to show a selectedItem at startup?

  • 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-22T15:51:49+00:00Added an answer on May 22, 2026 at 3:51 pm

    One problem I can see is that each time Users property is accessed, the RetrieveUsers() method is invoked which re-runs your database query. This is going to upset your SelectedItem binding which will expect the list of items bound to the ComboBox to be unchanged. In other words, it finds the selected item by evaluating the equality of the SelectedItem against the collection of bound items.

    You need to query the database once …

    public YourClassConstructor()
    {
       _users = _userRepository.RetrieveUsers();
       _selectedName = _users[0];
    }
    
    public List<User> Users
    {
        get
        {
            return _users;
        }
    }
    

    This will also ensure that the first item is selected.

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

Sidebar

Related Questions

I have this very simple Combobox in my XAML: <ComboBox Name=cmb1 Width=200 Height=23 ItemsSource={Binding}
I have the current Combo Box XAML: <ComboBox Height=23 HorizontalAlignment=Left ItemsSource={Binding ElementName=showDomainDataSource, Path=Data} Margin=583,8,0,0
I have a ComboBox whose xaml is as follows <ComboBox Name=ComboBoxDiscussionType IsEnabled={Binding ElementName=ComboBoxDiscussionType, Path=Items.Count,
i have an combox control defined with events in my mainpage.xaml <Grid x:Name=LayoutRoot> <ComboBox
I have the following XAML: <TextBlock Text={Binding ElementName=EditListBox, Path=SelectedItems.Count} Margin=0,0,5,0/> <TextBlock Text=items selected> <TextBlock.Style>
I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
I have following XAML (simplified, no ending tags): <Window Name=myWindow DataContext={Binding ElementName=myWindow} > <DockPanel>
I have a compbobox with the following information <ComboBox Margin=10,10,0,13 Name=ComboBox1 HorizontalAlignment=Left VerticalAlignment=Top Width=128
I have a custom combobox ( MyComboBox ) defined in my code (by making
I have the following defined at the top of my XAML: <controls:ChildWindow x:Class=MyProject.SilverlightUI.Views.CharacterGenerator xmlns:my=clr-namespace:MyProject.SilverlightUI.ViewModels

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.