Skip to main content

Microsoft Silverlight

Answered Question set selected item of combobox in dataform controlRSS Feed

(0)

saurabh951
saurabh951

Member

Member

17 points

36 Posts

set selected item of combobox in dataform control

in my silverlight 3.0 application

i have a combo box in side dataform control

<df:DataField Label="Type">

<ComboBox SelectedItem="{Binding Type, Mode=TwoWay}">

<ComboBoxItem Content="Employee"/>

<ComboBoxItem Content="Contractor"/>

</ComboBox>

</df:DataField>

 

now when i bind the data form how to set selected value of combo box as per the value in item source ???

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: set selected item of combobox in dataform control

What kind of data is in the Type field?

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

saurabh951
saurabh951

Member

Member

17 points

36 Posts

Re: set selected item of combobox in dataform control

Type field is having string data. and there is only two possible value "Employee" or "Contractor"

Min-Hong Tang - MSFT
Min-Hong...

Contributor

Contributor

3619 points

412 Posts

Answered Question

Re: set selected item of combobox in dataform control

 

 <UserControl.Resources>
     <my:ComBoValue x:Key="combovalue" />
 </UserControl.Resources>
 Hi,

   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  

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities