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

Setting ComboBox SelectedItem in MVVM

2 Answers 235 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 18 Feb 2011, 12:04 AM
I have a child window that contains a number of RadComboBoxes.  This child window has it's data context set to a ViewModel that has a number of properties on it.  Some of the properties are ObservableCollection<T> that are used as item sources for the RadComboBoxes.  All of these RadComboBoxes have their selected item property bound to properties on the ViewModel.  In our ViewModel's constructor, I'm injecting an instance of the class that our RadComboBoxes have their selected item properties bound to.  My assumption is that when the child window loads, since we're injecting an existing instance, the RadComboBoxes should have an initial value equal to whatever their corresponding properties are set to.  However this is not the behavior we're seeing.  Instead, all of the RadComboBoxes have blank initial values.

Any insight you could provide on resolving this would be appreciated.

Thanks!

Chris

2 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 22 Feb 2011, 03:34 PM
Hi Christopher,

 
Please, refer to the following forum thread - http://www.telerik.com/help/silverlight/radcombobox-features-selection.html

I hope this helps.

Greetings,
George
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Christopher
Top achievements
Rank 1
answered on 22 Feb 2011, 03:56 PM
Thanks, I found the solution on my own however.  It appears that it was an issue of timing.  I was trying to set the selected index in my view's ctor.  However the binding had not yet been established at this point, so I instead needed to set the selected index for each combobox in it's Loaded event.  Not a pretty solution, but it works.

Chris
Tags
ComboBox
Asked by
Christopher
Top achievements
Rank 1
Answers by
George
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or