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

Confirm on Delete

7 Answers 116 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Andreas Decke
Top achievements
Rank 1
Andreas Decke asked on 17 Apr 2011, 10:22 AM
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.

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Apr 2011, 07:38 AM
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
0
Leos
Top achievements
Rank 1
answered on 18 Apr 2011, 08:29 AM
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
0
Maya
Telerik team
answered on 19 Apr 2011, 02:40 PM
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
0
Leos
Top achievements
Rank 1
answered on 19 Apr 2011, 03:12 PM
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
0
Maya
Telerik team
answered on 19 Apr 2011, 04:20 PM
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
0
Leos
Top achievements
Rank 1
answered on 20 Apr 2011, 09:57 AM
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
0
Maya
Telerik team
answered on 20 Apr 2011, 11:45 AM
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
Tags
DataForm
Asked by
Andreas Decke
Top achievements
Rank 1
Answers by
Maya
Telerik team
Leos
Top achievements
Rank 1
Share this question
or