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

Binding SelectedValue and SelectedValuePath to Sub-Object Property

1 Answer 427 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert Kaucher
Top achievements
Rank 2
Robert Kaucher asked on 07 Jun 2012, 04:07 PM
My page's data context is set to an Instance of a Project class and all of the other fields in the page are working properly. Each project has another class associated with it as a property. This represents data from another company that we are integrating into this page.
I am attempting to bind to this sub object's TypeID property. Here is a sketch of the objects.
    
      public class Project
    {
        public int Id { get; set; }
        public string ProjectName { get; set; }
        public ABCProject ABCProject { get; set; }
    }
     
    public class ABCProject
    {
        public int Id { get; set; }
        public int ABCProjectTypeId { get; set; }
        public ABCProjectType { get; set; }
    }
     
    public class ABCProjectType
    {
       public int ProjectTypeId { get; set; }
       public string TypeName { get; set; }
    }

Here is what my XAML looks like:

<telerik:RadComboBox Grid.Column="2" Grid.Row="1" telerik:StyleManager.Theme="Metro" x:Name="ProjectTypeCombo"
                                 ItemsSource="{Binding ProjectTypePickList}"
                                 SelectedValue="{Binding ABCProject.ABCProjectTypeId, Mode=TwoWay}"
                                 SelectedValuePath="ABCProjectTypeId"
                                 DisplayMemberPath="TypeName"/>


The pick list is being bound properly. The issue is that the selected value and selected value path don't seem to be binding as I get a blank combobox when the page loads.

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 11 Jun 2012, 11:41 AM
Hi,

The issue with the RadComboBox is when the items are not loaded at once before the ItemsSource is set, the SelectedValue property won't work properly, as it tries only once to select the item, which might not be the first one. So the solution is to make sure that all items are loaded before you set the ItemsSource. More on the issue you could find in this forum discussion: http://www.telerik.com/community/forums/silverlight/combobox/selecteditem-not-in-itemssource.aspx#1969879

Hope this information helps. Please do not hesitate to contact us again if you have further questions.

All the best,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
ComboBox
Asked by
Robert Kaucher
Top achievements
Rank 2
Answers by
Konstantina
Telerik team
Share this question
or