This is a migrated thread and some comments may be shown as answers.

NewItemTemplate Commit event

7 Answers 102 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
peter
Top achievements
Rank 1
peter asked on 21 Nov 2011, 06:17 PM
I have a form which has two templates the edittemplate and the newitemtemplate. I also have the "Ok" button displaying. My problem is that this "OK" button seems to be wired up to the EditEnded event, how can i wire it up to the AddedNewItem event when the newitemtemplate is the template being displayed?

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 22 Nov 2011, 08:42 AM
Hi Peter,

Generally, the 'Ok' button executes commit edit command. Would you clarify what is the exact scenario that you want to achieve when inserting new item ? Do you want to execute similar command once a new item is about to be added or when its fields are updated and it is inserted in the data source collection ? 
  

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
peter
Top achievements
Rank 1
answered on 22 Nov 2011, 10:48 AM
Hi Maya,

I was hoping that when the edittemplate is displayed the "OK" button would trigger the editended event, and when the newitemtemplate is displayed the "OK" button would trigger the AddedNewItem event due to the fact I need to add new data to the database.

To give some context, i have wired the events to trigger some mvvm commands and at the moment both situations trigger the editended.
0
Maya
Telerik team
answered on 23 Nov 2011, 08:33 AM
Hello Peter,

This would be the expected behavior since in both cases (when editing an item and when adding a new one) the edit is ended and the corresponding event is fired. Actually, there is not AddedNewItem event supported by RadDataForm, only AddingNewItem is available for the time being. 
What I could suggest is to work with the EditEnded event and verify whether the current item is a new one just inserted in the collection or not. 
What is the data source collection you are working with ? 
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Art Kedzierski
Top achievements
Rank 2
answered on 17 Jul 2013, 08:24 PM
And how would one go about determining if the current item was just added to the ObservableCollection? And I'm using MVVM with WCF RIA services just to complicate things. Here's my current code which only handles changes to existing items:

<telerik:RadDataForm x:Name="locationDetail"
                        ItemsSource="{Binding Locations}"
                        CurrentItem="{Binding SelectedLocation, Mode=TwoWay}"
                        Grid.Column="1"
                        Grid.Row="1"
                        AutoGenerateFields="False"
                        EditTemplate="{StaticResource LocationEditItem}"
                        NewItemTemplate="{StaticResource LocationEditItem}"
                        ReadOnlyTemplate="{StaticResource LocationReadItem}"
                        Margin="-1,0,0,0"
                        CommandButtonsVisibility="Add, Edit, Navigation, Commit, Cancel">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="EditEnded">
            <ei:CallMethodAction TargetObject="{Binding}"
                                    MethodName="SaveLocation"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</telerik:RadDataForm>

public void SaveLocation()
{
    if (RepositoryFactory.Instance.Service.HasChanges == false)
    {
        return;
    }
    RepositoryFactory.Instance.Service.SubmitChanges(this.SubmitOperationCompleted, null);
}

0
Maya
Telerik team
answered on 18 Jul 2013, 12:53 PM
Hello Peter,

Actually, I discovered a mistake in my answer - there is AddedNewItem event that is thrown right after AddingNewItem event. If you want to check whether committing an edit is performed on the new item, you can try to perform a check similar to:

private void dataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
        {
            if (this.dataForm.Mode == Telerik.Windows.Controls.Data.DataForm.RadDataFormMode.AddNew && e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
            {
            }
        }

Will that work for you ?  

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Art Kedzierski
Top achievements
Rank 2
answered on 18 Jul 2013, 01:38 PM
How would you do that in a ViewModel and not code-behind? A ViewModel should have no knowledge of the view so this.dataForm.Mode is invalid.
0
Maya
Telerik team
answered on 18 Jul 2013, 02:10 PM
Hello Peter,

If your collection is IEditableCollectionView for example, you will have all the information required. Check out this article for a reference. 

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DataForm
Asked by
peter
Top achievements
Rank 1
Answers by
Maya
Telerik team
peter
Top achievements
Rank 1
Art Kedzierski
Top achievements
Rank 2
Share this question
or