RadDataForm and RadComboBox

3 posts, 0 answers
  1. Don
    Don avatar
    6 posts
    Member since:
    Sep 2007

    Posted 20 May 2011 Link to this post

    I have a RadDataForm using custom controls via a template and is bound and displays fine, I am having trouble populating the RadComboBoxes inside the RadDataForm and then having the correct item selected.  I am populating an observablecollection and setting that to the dataforms itemsSource. This works fine. I as well populate another observablecollection and attempt to set that to a radcombobox inside the raddataform by using RadDataForm.FindName("AppointmentTypeList") in the MainPage.xaml.cs.

    Also already read this and still not sure:
    http://www.telerik.com/help/silverlight/raddatafor-edit-lookup-values-with-radcombobox.html

    I suppose there is something with ViewModel, and I have no clue how to use this or have it interface with my object and the radcombobox.


    Environment Facts: Silverlight 4, Windows 7, iExplorer 8.0.7601.17514, RadControls_for_Silverlight_4_2011_1_0419, C#

    XAML:

     

    <DataTemplate x:Key="AppointmentItemTemplate" x:Name="AppointmentItemTemplate">
       <StackPanel Orientation="Horizontal" >
            <Grid Background="White">
             <TextBox HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="1" Grid.Column="1"
                                                 Margin="20,0,0,0" Width="250" 
                                                 x:Name="AppointmentTitle" 
                                                 Text="{Binding AppointmentTitle, Mode=TwoWay}" />
      
         <telerik:RadComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="4" Grid.Column="1"
                                     Name="AppointmentTypeList"                                                        
                                     SelectedValuePath="AppointmentAppointmentTypeId"
                                     DisplayMemberPath="AppointmentTypeName"/>
           </Grid>
       </StackPanel>
    </DataTemplate>
    <telerik:RadDataForm HorizontalAlignment="Left" VerticalAlignment="Top" Height="420" Width="520"
                                         Name="AppointmentTemplateForm" 
                                         Header="Appointment Template Form" 
                                         Visibility="Collapsed"
                                         AutoGenerateFields="False"
                                         ReadOnlyTemplate="{StaticResource AppointmentItemTemplate}"
                                         EditTemplate="{StaticResource AppointmentItemTemplate}"
                                         NewItemTemplate="{StaticResource AppointmentItemTemplate}"
                                         EditEnded="AppointmentTemplateForm_EditEnded">
    </telerik:RadDataForm>
    CS:
    //An observable collection is used to hold the items
     private ObservableCollection<AppointmentTypeItem> appointmentTypeItems;
    //Observable collection is populated via SOAP
    //Code not working – used to load items into the combobox
    RadComboBox appointmentTypesBox = (RadComboBox)AppointmentTemplateForm.FindName("AppointmentTypeList");
    appointmentTypesBox.ItemsSource = appointmentTypeItems;
      
    //Base Object Bound to DataForm:
    public class AppointmentTemplateItem
     {
            private EntityReference appointmentAppointmentTypeId; //Value used to select correct DropDown Item.
            public EntityReference AppointmentAppointmentTypeId { get { return this.appointmentAppointmentTypeId; } set {    
                                     this.appointmentAppointmentTypeId = value; } }
    }
      
    //Class that defines the object to be bound to the RadComboBox
    public class AppointmentTypeItem
    {
            private Guid appointmentTypeId;
            private String appointmentTypeName;
      
            public AppointmentTypeItem() { }
      
            public AppointmentTypeItem(Guid appointmentTypeId, String appointmentTypeName)
            {
                AppointmentTypeId = appointmentTypeId;
                AppointmentTypeName = appointmentTypeName;
            }
      
            public Guid AppointmentTypeId { get { return this.appointmentTypeId; } set { this.appointmentTypeId = value; } }
            public String AppointmentTypeName { get { return this.AppointmentTypeName; } set { this.appointmentTypeName = value; } }
    }

  2. Don
    Don avatar
    6 posts
    Member since:
    Sep 2007

    Posted 25 May 2011 Link to this post

    Can now bind the data to the ComboBox by adding the Loaded="AppointmentTypeList_Loaded"
    I was able to access the control and populate it in the codebehind


    XAML:

     

     

    <telerik:RadComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Row="4" Grid.Column="1" 
                                                             Margin="20,0,0,0" Width="250"
                                                             Name="AppointmentTypeList"                                                        
                                                             SelectedValuePath="AppointmentTypeId"
                                                             DisplayMemberPath="AppointmentTypeName"
                                                             ItemsSource="{Binding}"
                                                             SelectedValue="{Binding AppointmentAppointmentTypeId, Mode=TwoWay}"
                                                             Loaded="AppointmentTypeList_Loaded"/>
    CS:
    private void AppointmentTypeList_Loaded(object sender, RoutedEventArgs e)
    {
        RadComboBox currentComboBox = (RadComboBox)sender;
        currentComboBox.DataContext = appointmentTypeItems;  //Observable Collection
    }

    I am still unable to have the proper item selected.
    SelectedValue="{Binding AppointmentAppointmentTypeId, Mode=TwoWay}" is not working
    AppointmentAppointmentTypeId is an EntityReference (CRM 2011 Product) and not a GUID, which the appointmentTypeItems observable collection contains as the 'value' to match when binding.

     

  3. DevCraft banner
  4. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 26 May 2011 Link to this post

    Hi Don,

    I am attaching a small sample  application , based on your code .
    I have fixed a few things. Please use it as a starting point.

    Best wishes,
    Pavel Pavlov
    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
Back to Top