Hi,
I am using RadDataForm to insert/edit a new records.My main page has a radgrid bound to a QueryableDataServiceCollectionView<Document>, and a button for displaying a popup window for data insert.The poup window contains a RadDataForm with a DataTemplate.
When clicking the button 'New Driver Document'
, the RadDataForm in the poup winodw is bound to the same QueryableDataServiceCollectionView<Document> that I use for biniding the RadGridView.I also call RadDataForm.AddNewItem to insert the new record and then show the popup window.The RadGridView successfully responds to this call and shows a new empty record row.I fill in the form, save and close the poup and everything works fine, but If click the button 'New Driver Document' again, fill in the form
,and click save ,the saving is not done without any errors.
I Later switched to adding the item using QueryableDataServiceCollectionView<Document>.AddNewItem
instead of the RadDataForm.AddNewItem to see if that works.When I click the 'New Driver Document' for the first time
the QueryableDataServiceCollectionView<Document>.AddNewItem will return a valid Document object, and the form will save the record.If click again on the 'New Driver Document', the QueryableDataServiceCollectionView<Document>.AddNewItem will return null and the saving will not be done and without any errors!!!
My custom save button on the popup window calls an extension method that simply calls SubmitChanges on QueryableDataServiceCollectionViewBase
Thanks
Madani
I am using RadDataForm to insert/edit a new records.My main page has a radgrid bound to a QueryableDataServiceCollectionView<Document>, and a button for displaying a popup window for data insert.The poup window contains a RadDataForm with a DataTemplate.
<
telerik:RadGridView
Name
=
"RadGridView"
ItemsSource
=
"{Binding}"
CanUserFreezeColumns
=
"False"
AutoGenerateColumns
=
"False"
MouseDoubleClick
=
"RadGridView_MouseDoubleClick"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"ID"
DataMemberBinding
=
"{Binding ID}"
/>
<
telerik:GridViewDataColumn
Header
=
"Driver Name"
DataMemberBinding
=
"{Binding DriverDocument.Driver.FullName}"
/>
<
telerik:GridViewDataColumn
Header
=
"Document Number"
DataMemberBinding
=
"{Binding DocumentNo}"
/>
<
telerik:GridViewDataColumn
Header
=
"Issue Date"
DataMemberBinding
=
"{Binding IssueDate}"
/>
<
telerik:GridViewDataColumn
Header
=
"ExpiryDate"
DataMemberBinding
=
"{Binding ExpiryDate}"
/>
<
telerik:GridViewDataColumn
Header
=
"Place Of Issue"
DataMemberBinding
=
"{Binding PlaceOfIssue.Text}"
/>
<
telerik:GridViewDataColumn
Header
=
"Document Type"
DataMemberBinding
=
"{Binding DocumentType.Name}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
<
Button
Content
=
"New Driver Document"
Name
=
"NewBTN"
MinWidth
=
"180"
Click
=
"NewBTN_Click"
/>
When clicking the button 'New Driver Document'
, the RadDataForm in the poup winodw is bound to the same QueryableDataServiceCollectionView<Document> that I use for biniding the RadGridView.I also call RadDataForm.AddNewItem to insert the new record and then show the popup window.The RadGridView successfully responds to this call and shows a new empty record row.I fill in the form, save and close the poup and everything works fine, but If click the button 'New Driver Document' again, fill in the form
,and click save ,the saving is not done without any errors.
private void NewBTN_Click(object sender, RoutedEventArgs e)
{
DriverDocumentView view =
new
DriverDocumentView();
//popup window
view.DataContext = dataContext;
//this is the same as the radgrid itemssource
view.ShowPopup();
//this assigns the owner window and call show on the window
view.RadDataForm.AddNewItem();
view.RadDataForm.BeginEdit();
view.Focus();
}
I Later switched to adding the item using QueryableDataServiceCollectionView<Document>.AddNewItem
instead of the RadDataForm.AddNewItem to see if that works.When I click the 'New Driver Document' for the first time
the QueryableDataServiceCollectionView<Document>.AddNewItem will return a valid Document object, and the form will save the record.If click again on the 'New Driver Document', the QueryableDataServiceCollectionView<Document>.AddNewItem will return null and the saving will not be done and without any errors!!!
private void NewBTN_Click(object sender, RoutedEventArgs e)
{
DriverDocumentView view =
new
DriverDocumentView();
view.DataContext = dataContext;
// this is the same as the RadGridView ItemsSource
Document doc = dataContext.AddNewItem(
new
Document());
//this will return null if inserting the second record
dataContext.MoveCurrentTo(doc);
view.ShowPopup();
view.RadDataForm.BeginEdit();
view.Focus();
}
My custom save button on the popup window calls an extension method that simply calls SubmitChanges on QueryableDataServiceCollectionViewBase
MyRadDataForm.SubmitChanges();
public
static
void
SubmitChanges(
this
RadDataForm form)
{
if
(form.ItemsSource
is
QueryableDataServiceCollectionViewBase)
{
((QueryableDataServiceCollectionViewBase)form.ItemsSource).SubmitChanges();
}
}
Thanks
Madani