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

ComboBox DataBinding

2 Answers 76 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael Salzlechner
Top achievements
Rank 1
Michael Salzlechner asked on 19 Apr 2010, 05:35 PM
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 Answers, 1 is accepted

Sort by
0
Michael Salzlechner
Top achievements
Rank 1
answered on 20 Apr 2010, 01:37 PM
Well duh

found the problem

Binding should of course go to

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

and not SelectedItem as i had

Mike
0
Konstantina
Telerik team
answered on 22 Apr 2010, 12:31 PM
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.
Tags
ComboBox
Asked by
Michael Salzlechner
Top achievements
Rank 1
Answers by
Michael Salzlechner
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or