7 Answers, 1 is accepted
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
<
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
);
}
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
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 >>
If your collection is IEditableCollectionView for example, you will have all the information required. Check out this article for a reference.
Maya
Telerik
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 >>