Skip to main content
Home Forums Silverlight Design Designing with Silverlight set selected item of combobox in dataform control
3 replies. Latest Post by Min-Hong Tang - MSFT on November 5, 2009.
(0)
saurabh951
Member
17 points
36 Posts
11-03-2009 10:02 AM |
in my silverlight 3.0 application
i have a combo box in side dataform control
now when i bind the data form how to set selected value of combo box as per the value in item source ???
bryant
Star
9937 points
1,629 Posts
11-03-2009 5:28 PM |
What kind of data is in the Type field?
11-04-2009 5:33 AM |
Type field is having string data. and there is only two possible value "Employee" or "Contractor"
Min-Hong...
Contributor
3619 points
412 Posts
11-05-2009 10:27 PM |
<UserControl.Resources> <my:ComBoValue x:Key="combovalue" /> </UserControl.Resources>
When you set the combox's selectedItem , it will look for the item you set in it's itemsCollection if it's not found then it will still be null. And you add your combox's item in xaml so the itemCollection's type will naturally be typeof ComboxItem(If you use the c# way then the ItemsCollection's type will be your itemsSource's type). But here your Type Field's type is string. They can't be matched.
Here is how i archieved your requirement.
<UserControl.Resources> <my:ComBoValue x:Key="combovalue" /> // ComboValue is a class which contains a string[] Property </UserControl.Resources>
<dataFormToolkit:DataForm x:Name="df"> <dataFormToolkit:DataForm.ReadOnlyTemplate> <DataTemplate> <StackPanel> <ComboBox x:Name="cb" ItemsSource="{Binding MyValue,Source={StaticResource combovalue}}" SelectedItem="{Binding Type}"></ComboBox> </StackPanel> </DataTemplate> </dataFormToolkit:DataForm.ReadOnlyTemplate> </dataFormToolkit:DataForm>
Best Regards