Confirm on Delete

8 posts, 0 answers
  1. Andreas Decke
    Andreas Decke avatar
    25 posts
    Member since:
    Oct 2007

    Posted 17 Apr 2011 Link to this post

    Hello

    i will confirm before the record is deleted..

    private void DataFormMonitor_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
    {
      try
      {
        CurrentMonitor = DataFormMonitor.CurrentItem as SDLmedia_ComputerMonitor;
        if (CurrentMonitor != null)
        {
          DialogParameters dp = new DialogParameters();
          dp.Header = "Monitor";
          dp.Content = string.Format("Monitor \"{0}\" löschen?", CurrentMonitor.Title);
          dp.ModalBackground = Common.GetModalBg();
          dp.Closed = (so, se) =>
          {
            if (se.DialogResult == false)
            {
              e.Cancel = true;
            }
          };
          RadWindow.Confirm(dp);
        }
      }
      catch (Exception exc)
      {
        Error.CreateNew(exc, ErrorTitle);
      }
    }

    The Record is deleted before the RadWindow.Confirm Dialog is execute!
    Please, how can Confirm the Record before the Record is deleted?

    thanks.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 18 Apr 2011 Link to this post

    Hi Richard Crowley,

    Generally, when you open up a RadWindow, the current thread does not stop its execution. Consequently, the item is deleted event if a window is displayed. What you may try to do is to cancel the deletion in the DeletingItem event and remove the current item from the collection once the user confirmed it.

    private void myRadDataForm_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
            {
                RadWindow.Confirm("Zdrasti pesho", wnd_Closed);        
                e.Cancel = true;               
            }
     
    void wnd_Closed(object sender, WindowClosedEventArgs e)
            {
                if((sender as RadWindow).DialogResult == true)
                {
                    IList<Employee> myItems = this.myRadDataForm.ItemsSource as IList<Employee>;
                    myItems.Remove(this.myRadDataForm.CurrentItem as Employee);
                }          
            }
     

    Greetings,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 18 Apr 2011 Link to this post

    Hi,
    I have some problems with this code, it seems that it is not working with WCF.RIA.
    I used this (same way but other Collection):
    /** if user will confirm remove of record then we remove it here manually */
    private void OnDialogClosed(object sender, WindowClosedEventArgs e)
    {          
      if ( (sender as RadWindow).DialogResult == true)
       {               
          DataItemCollection myItems = (DataItemCollection)this.rdf.ItemsSource;
          myItems.Remove(this.rdf.CurrentItem as DiaryRecord);
          rdds.SubmitChanges(); // force submit change here (OnDeletedItem is not called)
       }           
    }

    I also modified example to use remove confirmation with RadWindow:
    http://qds.aspone.cz/DiaryExample/DiaryExampleTestPage.aspx
    http://qds.aspone.cz/DiaryExample/DiaryExampleAspone.pdf
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Apr 2011 Link to this post

    Hi Richard Crowley,

    I have tested the sample you provided and everything seems to work quite correct - once I delete an item from the data form, a new window is displayed. After pressing Ok button, the very same item is removed both from the data form and the grid.
    So, may you give a bit more information about the exact undesired behavior that you experience ? What are the issues that you encountered ? 
     

    Greetings,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 19 Apr 2011 Link to this post

    Maya,
    sorry. My bad English leads to the misunderstanding. (I assume that your comment is related to my post, not to original Richard post).

    Original post:
    I have some problems with this code, it seems that it is not working with WCF.RIA.
    I used this (same way but other Collection):

    Must be:
    I have some problems with Maya's code (with IList), it seems that it is not working with WCF.RIA.
    I used this code (with DataItemCollection) and it is working with WCF.RIA (same way but other Collection):

    Sorry again for your time.
    Leos
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Apr 2011 Link to this post

    Hello Leos,

    Indeed, I was referring to your post - please accept my apology for the misunderstanding.  
    If you want to perform the same logic when using a domain data source and RIA Services, you may do the following:

    private void customersDataForm_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
            {
                RadWindow.Confirm("Do you really want to delete the item?", wnd_Closed);
                e.Cancel = true; 
            }
            void wnd_Closed(object sender, WindowClosedEventArgs e)
            {
                if ((sender as RadWindow).DialogResult == true)
                {
                    this.customersDataSource.DataView.Remove(this.customersDataForm.CurrentItem as Customer);
                    this.customersDataSource.SubmitChanges();
                }
            }

    Please let me know whether is corresponds to your requirements.

    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Leos
    Leos avatar
    57 posts
    Member since:
    Jul 2010

    Posted 20 Apr 2011 Link to this post

    Thanks Maya.

    Is here some advantage to use:
    rdds.DataView.Remove(this.rdf.CurrentItem as DiaryRecord);

    over

    DataItemCollection myItems = (DataItemCollection)this.rdf.ItemsSource;
    myItems.Remove(this.rdf.CurrentItem as DiaryRecord);
    ??

    Except lower amount of lines of code?

    By other words:
    For me both variants are working.
    I write this comment because I want to know if here are some hidden troubles with my way :)

    Leos
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Apr 2011 Link to this post

    Hi Leos,

    Generally, the correct implementation depends on your scenario. However, there should be no difference between my suggestion and yours. In both cases, you need to call SubmitChanges() method so that the item is removed from the data source. 


    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft banner