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
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); } }Maya
the Telerik team
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
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 ?
Maya
the Telerik team
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
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
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
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.
Maya
the Telerik team