ComboBox DataBinding

3 posts, 0 answers
  1. Michael Salzlechner
    Michael Salzlechner avatar
    41 posts
    Member since:
    Jan 2010

    Posted 19 Apr 2010 Link to this post

    I am using the RadComboBox to show a list of countries in a data entry screen

    the items are bound to an observable collection that contains a list of country objects that have a Name as well as a Code property ("United States", "US")

    I set the ItemsSource to the observable collection and the DisplayMemberPath to "Name"

    Now on the other hand i want to bind the SelectedItem to a database field on the screen. The parent is data bound and i simply set the

     

     

     

    SelectedItem="{Binding CountryCode, Mode=TwoWay}" 
     

     

     

     

     


    which works fine for a simple standard combobox without name/code pairs

    Now with the RadCombo it doesnt show the value from the database. When i select an item in the combo i have to select it twice to show the name and when i reopen the screen even though the values are saved in the database the name is not shown in the combobox

     

            private ObservableCollection<Country> countries;  
            public ObservableCollection<Country> Countries                      
            {  
                get 
                {  
                    if (countries == null)  
                    {  
                        countries = new ObservableCollection<Country>();  
     
                        countries.Add(new Country("Austria""AT"));  
                        countries.Add(new Country("United States""US"));  
                        countries.Add(new Country("Canada""CA"));  
                    }  
     
                    return countries;  
                }  
            } 

     

     

            public mfgr_AddEdit()  
            {  
                // Required to initialize variables  
                InitializeComponent();  
     
     
                  
                CountryCombo1.ItemsSource = Countries;  
                CountryCombo1.DisplayMemberPath = "Name";  
                CountryCombo1.SelectedValuePath = "Code";  
            } 

    // ------------------------------------------

    am i missing something ?

    thanks

    Mike

     

  2. Michael Salzlechner
    Michael Salzlechner avatar
    41 posts
    Member since:
    Jan 2010

    Posted 20 Apr 2010 Link to this post

    Well duh

    found the problem

    Binding should of course go to

    SelectedValue="{Binding CountryCode, Mode=TwoWay}" 

    and not SelectedItem as i had

    Mike
  3. DevCraft banner
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 22 Apr 2010 Link to this post

    Hello Michael,

    We are glad that you have resolved the issue yourself.

    If you have any other questions please let us know.

    All the best,
    Konstantina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top