This is a migrated thread and some comments may be shown as answers.

how to use SelectedValuePath

3 Answers 307 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alex Wu
Top achievements
Rank 1
Alex Wu asked on 15 Dec 2009, 07:27 AM
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>

3 Answers, 1 is accepted

Sort by
0
Accepted
Konstantina
Telerik team
answered on 15 Dec 2009, 12:30 PM
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.
0
Alex Wu
Top achievements
Rank 1
answered on 15 Dec 2009, 02:47 PM
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








0
Alex Wu
Top achievements
Rank 1
answered on 16 Dec 2009, 05:31 AM
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
Tags
ComboBox
Asked by
Alex Wu
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Alex Wu
Top achievements
Rank 1
Share this question
or