how to use SelectedValuePath

4 posts, 1 answers
  1. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 15 Dec 2009 Link to this post

    Can someone please tell me why the following code doesn't work? I expect that when the value is set to "False" the 2nd item would be selected when the silverlight page initially loads but it doesn't work. It's always null...ie. No item selected.

                <my:RadComboBox x:Name="BooleanValue" DisplayMemberPath="Content" SelectedValue="False">
                    <my:RadComboBoxItem Content="True" />
                    <my:RadComboBoxItem Content="False" />
                </my:RadComboBox>
  2. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 15 Dec 2009 Link to this post

    Hello Alex,

    Straight to your question. Instead of the property DisplayMemberPath to be set to Content, you should set the SelectedValuePath="Content". This way the SelectedValue property will work as expected. The DisplayMemberPath property is used when you bind the ComboBox to some kind of a data source.

    If you have any further questions please feel free to ask again.

    Greetings,

    Konstantina
    the Telerik team

     


    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 15 Dec 2009 Link to this post

    I am actually asking this question because I am having problem with databinding combobox. I thought making it simple would be easier for people to understand what I am trying to do. Here is my real case.

    I have a viewModel with a property:
            public IEnumerable<Def_Company> Def_Companies
            {
                get
                {
                    _vmContext.Load(_vmContext.GetDef_CompanyQuery());
                    return (IEnumerable<Def_Company>)_vmContext.Def_Companies;
                }
            }

    In my App.XAML I have a static resorce:
     <viewModel:DefVewModel x:Key="app_vmDef"></viewModel:DefVewModel>

    IN my Company.xaml page I have a combobox with databinding:
    <my:RadComboBox x:Name="cboCompany" ItemsSource="{Binding Path=Def_Companies,Source={StaticResource app_vmDef} }" DisplayMemberPath="Name" SelectedValuePath="Id"  SelectedValue="{Binding CompanyId, Mode=TwoWay}"></my:RadComboBox>

    The combobbox populates properly from the static resouce but the "SelectedValue" binding doesn't work. I event tried to hard code the selected value like "SelectedValue=1" expecting the first item to be selected upon page load since the id of the first item is 1 but it's not working.

    Thanks








  4. Alex Wu
    Alex Wu avatar
    31 posts
    Member since:
    Dec 2009

    Posted 15 Dec 2009 Link to this post

    Since your answer solved my first question I am going to close this one and open a new thread for my 2nd question. Thank you
Back to Top