Confirm Delete

12 posts, 1 answers
  1. Travis
    Travis avatar
    223 posts
    Member since:
    Jan 2003

    Posted 30 Aug 2010 Link to this post

    Is there a way to confirm the user really wants to delete a record in the grid when they click on the delete key?
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 Aug 2010 Link to this post

    Hi Travis,

     You can use Deleting event to achieve this. Here is an example:

    private void RadGridView_Deleting(object sender, Telerik.Windows.Controls.GridViewDeletingEventArgs e)
            {
                var result = MessageBox.Show("Test", "Test", MessageBoxButton.OKCancel);
                e.Cancel = (result == MessageBoxResult.Cancel);
            }

    Sincerely yours,
    Vlad
    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. Travis
    Travis avatar
    223 posts
    Member since:
    Jan 2003

    Posted 02 Sep 2010 Link to this post

    The deleting event handler is not fired when the "Delete" key is pressed.  The ItemsSource of the GridView is using RIA.  I don't know if that makes a difference or not.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Sep 2010 Link to this post

    Hello,

     How the grid is bound in your case? If you use DomainDataSource everything should work as expected. 

    Sincerely yours,
    Vlad
    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. lee_bnsf
    lee_bnsf avatar
    16 posts
    Member since:
    Apr 2007

    Posted 03 Sep 2010 Link to this post

    I'm have a similar situation.  Is there a way to get the grid to respond to the delete key without being bound to a DomainDatasource; or in my case bound to a read-only entity in a DomainDatasource?

    Thanks,
    Lee
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Sep 2010 Link to this post

    Hello,

     If the grid is not bound at least to IList you will unable to add and remove items and that is why the event will not be raised. 

    Kind regards,
    Vlad
    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. lee_bnsf
    lee_bnsf avatar
    16 posts
    Member since:
    Apr 2007

    Posted 03 Sep 2010 Link to this post

    Thanks Vlad. As soon as I posted this I saw that my grid did not the CanUserDeleteRows property set to true.  When I updated that everything worked as expected.  Rookie mistake. :(
    Thanks,
    Lee
  9. Travis
    Travis avatar
    223 posts
    Member since:
    Jan 2003

    Posted 07 Sep 2010 Link to this post

    It is working now.  Not sure what I was doing wrong the first time.
  10. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Apr 2013 Link to this post

    I feel lucky this time.

    What if I'm in the Deleting Event and even before asking the user to confirm, the line is already deleted from the UI because I hit Delete from the keyboard on a line

    When I say NO and I code e.Cancel = true, it doesn't any good.

    I'm using version 2013.1.403.1050
    Here's the code :

    private void rgvExpenses_Deleting(object sender, GridViewDeletingEventArgs e)
    {
        // Huh ? The line is already deleted from the UI.  I can see it while the confirmation is on screen
        RadWindow.Confirm("Are you sure ?", (s, ee) =>
            {
                if (ee.DialogResult.Value)
                    e.Cancel = false;       // I suppose this means don't cancel the delete because I said YES which the ee.DialogResult means I've pressed YES
                else
                    e.Cancel = true;        // I suppose this should cancel the delete but he huh the delete was already performed.  What am I missing ?
            });
    }
  11. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009
  12. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Apr 2013 Link to this post

    After reading the article,  I don't know why but I feel like there's a problem somehow.
    How it comes to be called DELETING and yet the line is deleted even before I'm asking a confirmation in the Deleting event ?

    It bugs me. 
  13. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Apr 2013 Link to this post

    I think I get it.  Here's my version.  Don't forget to add a reference to System.Windows.Data
    private void rgvExpenses_Deleting(object sender, Telerik.Windows.Controls.GridViewDeletingEventArgs e)
    {
        e.Cancel = true;
     
        RadWindow.Confirm("Certain ?", (s, ee) =>
        {
            if (ee.DialogResult.Value)
            {
                foreach (var Expense in e.Items)
                    rgvExpenses.Items.Remove(Expense);
     
                e.Cancel = false;
            }
        });
    }
Back to Top
DevCraft banner