Combo Box in DataForm - Selected Value Never shows on Load

3 posts, 1 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 30 Jan 2012 Link to this post

    Hi..
    I have the following ComboBox in a DataForm and in the Edit Template.  The value shows fine in the Read Only Template. But when I Bind the current values does not show and is not selected. The value SUBTYPE has a corresponding value in the Item Source. The dropdown displays the correct values and I can make a selection. But when loaded the ComboBox is blank and the value not selected.
    Any idea what I'm doing wrong?   thanks!!!!!!!!!!!!!!!!!!!!

         <telerik:RadComboBox x:Name="comboSubType" Margin="5,0,0,0"  Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" IsEnabled="True" HorizontalAlignment="Left" CanAutocompleteSelectItems="true"
                                                        ItemsSource ="{Binding SubCategories_Filtered,Source={StaticResource ViewModel}}"
                                                        SelectedValue="{Binding SubType, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                                                        SelectedValuePath="SubCategory1" 
                                                        DisplayMemberPath="SubCategory1" 
                                                        Style="{StaticResource RadComboBoxStyle}" Loaded="comboSubType_Loaded"
                                                        Height="30" Width="200" >


                                    </telerik:RadComboBox>

    SubCategories_Filtered looks like this

       private List<SubCategory> _filteredsubcatgories;
            public List<SubCategory> SubCategories_Filtered
            {
                get
                {
                    if (_filteredsubcatgories == null)
                    {
                        this.SubCategories_Filtered = new List<SubCategory>();


                    }


                    return _filteredsubcatgories;
                }
                set
                {
                    _filteredsubcatgories = value;
                    this.RaisePropertyChanged("SubCategories_Filtered");
                }
            }


    and this...

     [MetadataTypeAttribute(typeof(SubCategory.SubCategoryMetadata))]
        public partial class SubCategory
        {


            // This class allows you to attach custom attributes to properties
            // of the SubCategory class.
            //
            // For example, the following marks the Xyz property as a
            // required property and specifies the format for valid values:
            //    [Required]
            //    [RegularExpression("[A-Z][A-Za-z0-9]*")]
            //    [StringLength(32)]
            //    public string Xyz { get; set; }
            internal sealed class SubCategoryMetadata
            {


                // Metadata classes are not meant to be instantiated.
                private SubCategoryMetadata()
                {
                }


                public string Category { get; set; }


                public int ID { get; set; }


                public string SubCategory1 { get; set; }
            }
        }

  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Jan 2012 Link to this post

    Hi Jon,

    Do you experience this behavior only on loading ? Can you select an item from the combo box when editing? Generally, such a behavior may be caused by the fact that the value to be displayed as selected is not available at the time RadComboBox tries to find it (at the initial moment).  

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 31 Jan 2012 Link to this post

    Thanks.. yes that appears to be issue..
    The value is not available when loading...  The item source is null and not loaded.
    I changed the code and it works now...thanks for the response.
Back to Top