Insert will not work the second time

6 posts, 0 answers
  1. HCT-CERT
    HCT-CERT avatar
    22 posts
    Member since:
    Aug 2012

    Posted 26 Nov 2012 Link to this post

    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.

    <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 
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Nov 2012 Link to this post

    Hi Madani ,

    Despite of your detailed explanation on how RadGridView and RadDataForm  are used , we have some troubles identifying what exactly is the problem you are experiencing .

    You say  "the saving is not done without any errors" . So what are the errors you get ?

    Since your project involves some complex logic involving several controls I would highly recommend to open a support ticket , attaching a repro project that demonstrates the issue. This way we can rapidly identify the issue ( by debugging your runnable code ) and propose a descent solution in a timely manner.

    Kind regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. HCT-CERT
    HCT-CERT avatar
    22 posts
    Member since:
    Aug 2012

    Posted 04 Dec 2012 Link to this post

    Hi Pavel,

    As I said, the record is not saved, and that's why I am posting a question in this forum !!!.I am really tired because of the RadDataForm control. This control is full of bugs and I spend my hours fixing them simply because telerik support in this forum is very poor.It takes 3 or 4 days which is almost a week to get an "answer" in this forum.!!!.There is not a single example on how to use the form with WCF data services!!!.

    Back to my question:

    after more testing, I found that the second time a new item is added, the context does not track it, so I had to attach the item before calling SaveChanges.

    Another problem I am facing now is that after saving,the form keeps going back to the first record in the collection whereas it should keep displaying the newly created record.

    Thanks

    Madani





  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 05 Dec 2012 Link to this post

    Hello Madani,

    I am really sorry to hear about your frustration. In order to benefit from guaranteed priority support, you can use our support ticket system, which provides 24 hours response time for our customers. As for the inquiry of yours, I have prepared a sample project, in order to test the described behavior, but without any success in reproducing the reported issues. Could you please have a look at my example project and try to reproduce them there? You can either modify it and send the updated version back via a support ticket or give us some guidelines to reproduce it on our side. 

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. HCT-CERT
    HCT-CERT avatar
    22 posts
    Member since:
    Aug 2012

    Posted 04 Feb 2013 Link to this post

    Thanks Ivan, but the example you sent is very basic, and does not address any of the real scenarios we use in our application.Your example would be helpful if :

    • The Grid and the New Button are in the main page
    • Clicking the New Button opens the form in a new popup window
    • The buttons in the form are custom ones and not part of the command bar
    • When saving an insert, the Save button should keep displaying the newly create record (probably in read only mode) and not go back to the last displayed record.

    The documentation lacks examples of using the form in real life applications, and all examples rely on the built-in command bar which is not fit for custom applications.

    Regards,

    Madani
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 05 Feb 2013 Link to this post

    Hi,

    I have just posted a reply in the other thread of yours. May I ask you to continue our future communication there, so that we would be able to achieve more consistent dialogue?

    All the best,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready