How to call Edit command for RadDataForm?

4 posts, 0 answers
  1. saravanakumar subramaniam
    saravanakumar subramaniam avatar
    28 posts
    Member since:
    May 2010

    Posted 12 Dec 2011 Link to this post

    Hi,

    I am using RadDataForm to show the Employee details. I have enabled Add, Edit, Delete, Save and Commit command buttons for the RadDataForm and it is working fine. Now i have added separate button called "NewEdit". If i click the this new button i need to move the RadDataForm to Edit mode and if click "NewSave" i need to save the Employee details.

    In RadDataForm i did find any event to rise from the custom button click event. Is there any way to achieve this?
  2. HDC
    HDC avatar
    214 posts
    Member since:
    Dec 2010

    Posted 23 Dec 2011 Link to this post

    The only way that i found how to do this is by overriding the control template, here is how to do this:

    http://www.telerik.com/help/silverlight/raddatafor-styles-and-templates-styling-raddataform.html

    Create a class based on the RadDataForm:
    public class ExqiDataForm : RadDataForm  {
        public static readonly DependencyProperty SaveCommandProperty = DependencyProperty.RegisterAttached(
            "SaveCommand",                  
            typeof(object),             
            typeof(ExqiDataForm),
            null);
      
        public object SaveCommand
        {
          get
          {
            return (object)GetValue(SaveCommandProperty);
          }
          set
          {
            base.SetValue(SaveCommandProperty, value);
            //NotifyPropertyChanged("SaveCommand");
          }
        }
     
        public static readonly DependencyProperty SaveCommandParameterProperty = DependencyProperty.RegisterAttached(
            "SaveCommandParameter",
            typeof(object),
            typeof(ExqiDataForm),
            null);
     
     
        public object SaveCommandParameter
        {
          get
          {
            return (object)GetValue(SaveCommandParameterProperty);
          }
          set
          {
            base.SetValue(SaveCommandParameterProperty, value);
            //NotifyPropertyChanged("SaveCommandParameter");
          }
        }
     
      }

    From the template created with blend, change the target type to the above class:

    <ControlTemplate x:Key="RadDataFormTemplate" TargetType="custom:ExqiDataForm">

    You can then change the Part_FooterPanel:

    <Border x:Name="FooterPanel_Background" Background="{StaticResource DataForm_FooterPanel_Background}" Grid.Row="4">
    <StackPanel x:Name="PART_FooterPanel" HorizontalAlignment="Right" Orientation="Horizontal">
                <telerik:RadButton x:Name="PART_SaveButton" Content="Save"
                                   Command="{TemplateBinding SaveCommand}"
                                   CommandParameter="{TemplateBinding SaveCommandParameter}"
                  Margin="2,4,4,4" MinWidth="48" MinHeight="20" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="{Binding CommitButtonVisibility}"/>
               <telerik:RadButton x:Name="PART_CommitButton" Content="{TemplateBinding CommitButtonContent}" Command="controls:RadDataFormCommands.CommitEdit" Margin="2,4,4,4" MinWidth="48" MinHeight="20" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="{Binding CommitButtonVisibility}"/>
               <telerik:RadButton x:Name="PART_CancelButton" Content="{TemplateBinding CancelButtonContent}"    Command="controls:RadDataFormCommands.CancelEdit" Margin="2,4,4,4" MinWidth="48" MinHeight="20" telerik:StyleManager.Theme="{StaticResource Theme}" Visibility="{Binding CancelButtonVisibility}"/>
    </StackPanel>
    </Border>

    In the above code i added the save button.

    This is how you would then hook that up to the actual dataform

    <custom:ExqiDataForm  x:Name="OrganizationUsersEditor"
            ItemsSource="{Binding DataView, ElementName=organizationUserDomainDataSource}"
            AutoGenerateFields="False"
            AutoEdit="True"
            AutoCommit="True"                                     
            CommandButtonsVisibility="Edit,Cancel,Commit"
            LabelPosition="Above"
            EditEnded="RadDataFormEditEnded" Width="840" Height="550"
            Style="{StaticResource RadDataFormStyle}"
            SaveCommand="{Binding SaveCommand, Source={StaticResource vmOrganizationUser}}"   
            SaveCommandParameter="{Binding ElementName=organizationUserDomainDataSource}"
            >

    The "style" property is key here, you need to put the name of the style you created in blend.

    I know that it is kind of complicated, but it is the only way that i know

    Best Regards,

    Peter



  3. DevCraft banner
  4. Jeff
    Jeff avatar
    28 posts
    Member since:
    Aug 2010

    Posted 11 Feb 2012 Link to this post

    Is this seriously the only way to do it??
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Feb 2012 Link to this post

    Hi,

    You can use the built-in commands from RadDataFormCommands like BeginEdit and CommitEdit. Depending on where you want to place those buttons, you can either edit the template of RadDataForm and place them next to Ok and Cancel buttons or define them just below/above the data form.
    The most appropriate approach is up to your specific requirements.

     

    Kind regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top