locked
Silverlight and CRM 2011 : Binding OptionSetValues to a Silverlight ComboBox RRS feed

  • Question

  • Hi guys,

    I am having a bit of an issue with the above mentioned topic line.

    I have the below in my MainPage.xaml:

    <sdk:DataGrid x:Name="dgData" SelectionMode="Single" ItemsSource="{Binding Mode=OneTime}"
            AutoGenerateColumns="False" Height="Auto" Width="Auto" Visibility="Visible"
            Margin="14,0,12,31" Grid.Row="1">
     <sdk:DataGrid.Columns>
      
      <sdk:DataGridTemplateColumn Header="Name - Test">
       <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
         <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
          <TextBox Text="{Binding UserID, Mode=OneWay}" IsReadOnly="True"/>
         </StackPanel>
        </DataTemplate>
       </sdk:DataGridTemplateColumn.CellTemplate>
       <sdk:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
         <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
          <TextBox Name="UserName" />
         </StackPanel>
        </DataTemplate>
       </sdk:DataGridTemplateColumn.CellEditingTemplate>
      </sdk:DataGridTemplateColumn>
      <sdk:DataGridTemplateColumn Header="Lookup">
       <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
         <Button Name="LookupButton" Content="..." Width="Auto" Height="Auto"  Click="LookupButton_Click"/>
        </DataTemplate>
       </sdk:DataGridTemplateColumn.CellTemplate>
      </sdk:DataGridTemplateColumn>
      <sdk:DataGridTemplateColumn Header="Status - Test">
       <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
         <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
          <sdk:Label DataContext="{Binding Status, Mode=OneWay}" />
         </StackPanel>
        </DataTemplate>
       </sdk:DataGridTemplateColumn.CellTemplate>
       <sdk:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
         <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
          <ComboBox Name="cbxApproval" Width="120" ItemsSource="{Binding}" DisplayMemberPath="Value"/>
         </StackPanel>
        </DataTemplate>
       </sdk:DataGridTemplateColumn.CellEditingTemplate>
      </sdk:DataGridTemplateColumn>                
     </sdk:DataGrid.Columns>
    </sdk:DataGrid>

    The issue i am now having is getting the Element of the ComboBox "cbxApproval" in my C# code so I can bind the retrieved OptionSetValues to the ComboBox.

    Any assistance is highly appreciated.

    Regards

    Hopeful

    Wednesday, February 29, 2012 1:05 PM

Answers

  • Hi

    Like UserID, Status create one more attribute (MyListOfObjects) for optionset values of type List<OptionSet> in the binding class.

    for each binding class add the optionset values to new attribute

    **** binding class ****

    MyBindingClass bindingClass = new MyBindingClass();
    bindingClass.MyListOfObjects =list option set// Your call to get the data

    *** XAML code ***

    <ComboBox Name="cbxApproval" Width="120" ItemsSource="{Binding MyListOfObjects}" DisplayMemberPath="Value"/>

    *****class for optionset****

    public class OptionSet

    {

    public string Name{get; set;}

    public int Value{get; set;}

    }

    try this http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/85c19a6e-9bb1-4a63-a983-6e506b93dba9


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)


    • Proposed as answer by Nar_mscrm Wednesday, February 29, 2012 1:50 PM
    • Edited by Nar_mscrm Wednesday, February 29, 2012 1:54 PM
    • Marked as answer by _Hopeful Monday, March 12, 2012 9:29 AM
    Wednesday, February 29, 2012 1:49 PM

All replies

  • Hi

    Like UserID, Status create one more attribute (MyListOfObjects) for optionset values of type List<OptionSet> in the binding class.

    for each binding class add the optionset values to new attribute

    **** binding class ****

    MyBindingClass bindingClass = new MyBindingClass();
    bindingClass.MyListOfObjects =list option set// Your call to get the data

    *** XAML code ***

    <ComboBox Name="cbxApproval" Width="120" ItemsSource="{Binding MyListOfObjects}" DisplayMemberPath="Value"/>

    *****class for optionset****

    public class OptionSet

    {

    public string Name{get; set;}

    public int Value{get; set;}

    }

    try this http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/85c19a6e-9bb1-4a63-a983-6e506b93dba9


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)


    • Proposed as answer by Nar_mscrm Wednesday, February 29, 2012 1:50 PM
    • Edited by Nar_mscrm Wednesday, February 29, 2012 1:54 PM
    • Marked as answer by _Hopeful Monday, March 12, 2012 9:29 AM
    Wednesday, February 29, 2012 1:49 PM
  • Hi Hopeful,

    I am also trying the same problem. CRM 2011, Silverlight, DataGrid as source of Entity and ComboBox as source of OptionSetValues.

    If you have solved, please send me the sample code.

    Thanks,

    Mohan 

    Thursday, July 12, 2012 6:14 AM