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

The Archive Base Latest Questions

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

Why is that whenever I try to put SlectedIndex to 0, it always remains

  • 0

Why is that whenever I try to put SlectedIndex to 0, it always remains -1 ?

public partial class Window1 : Window
{
    private ObservableCollection<string> _dropDownValues = new ObservableCollection<string>();
    public ObservableCollection<string> DropDownValues
    {
        get { return _dropDownValues; }
        set { _dropDownValues = value; }
    }

    private string _selectedValue;
    public string SelectedValue
    {
        get { return _selectedValue; }
        set { _selectedValue = value; }
    }

    public Window1()
    {
        InitializeComponent();
        DataContext = this;

        DropDownValues.Add("item1");
        DropDownValues.Add("item2");
        DropDownValues.Add("item3");
        DropDownValues.Add("item4");
        DropDownValues.Add("item5");
        DropDownValues.Add("item6");

        if (combotest.SelectedIndex == -1)
        {
            combotest.SelectedIndex = 0;
        }
    }
}

<StackPanel HorizontalAlignment="Left" Margin="10">
        <ComboBox Name="combotest"
            Margin="0 0 0 5"
            ItemsSource="{Binding DropDownValues}"
            SelectedValue="{Binding SelectedValue}"        
            Width="150"/>     
    </StackPanel>
  • 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-25T10:34:04+00:00Added an answer on May 25, 2026 at 10:34 am

    Please correct me if I am wrong, but you havent set the SelectedValuePath in your XAML. Also once you set SelectedValuePath, you only need to set the default SelectedValue (same as the first item’s value property from your items source) and there is no need for your SelectedIndex code.

    Let me know if this helps.

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

Sidebar

Related Questions

Whenever I use WCF, I always try to make immutable classes that end up
I'm making a simple test app that navigates a category tree. Whenever I try
The problem I have is that whenever I try to drag and drop with
i try to put a lock to a static string object to access to
I want that whenever the user types http://localhost:8280/services/Facebook/sea the actual request should be http://localhost:8280/services/Facebook/search?q=jack
The author wrote that whenever the value of point changes the value of myRect's
I would like that whenever I run git diff or git show it silently
I know that whenever you add/remove/modify any file in the App_Code, App_GlobalResources, and bin
I have a web page that whenever your in a text-field, if you hit
Would it be correct to say that whenever casting is used, the resulting object

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.