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

remove multiple rows in a batch

2 Answers 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Technik
Top achievements
Rank 1
Technik asked on 10 Feb 2010, 02:56 PM
Hi,
i want to remove a batch of rows with a single confirmation dialog. Currently im using the RowsChaning event, but this fires for every deleted row, so the confirmation dialog pops up every time.

Is it possible to do a batch remove with a single dialog?

Winforms Q3 2009
Grid settings: MultipleSelect=true
Event used currently: RowsChaning
Datasource = bindinglist(of ...)

Here is my code:
----------------------

 
Private  
 
   
 
Sub gvMails_RowsChanging(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles gvMails.RowsChanging   
   
 
 
 
 
   
If  
 
   
 
e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.Remove Then   
   
 
 
 
   
 
If gvMails.SelectedRows.Count = 1 Then   
   
 
 
 
e.Cancel =   
 
Not DeleteMessageBox(gvMails.SelectedRows(0).DataBoundItem)   
   
 
   
 
 
 
Else   
   
 
 
 
e.Cancel =   
 
Not DeleteMessageBox()   
   
 
   
 
 
 
End If   
   
 
 
 
   
 
End If   
   
 
   
 
   
 
 
 
   
 
   
 
End Sub  
 
   
   
 
Private  
 
   
 
Function DeleteMessageBox() As Boolean   
   
 
 
 
   
 
If MsgBox("Delete all?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then  
   
   
 
    For  
 
   
 
Each itm In gvMails.SelectedRows   
   
 
   
 
 
 
        ' delete single msg  
    Next  
    return True  
 
   
 
 
 
End If   
   
 
 
 
   
 
Return False   
   
 
   
End  
 
   
 
Function   
   
 
 
 
   
 
   
 
 
 
   
   
 
Private  
 
   
 
 
 
Function DeleteMessageBox(ByVal msg As Message) As Boolean   
   
 
 
 
   
 
If MsgBox("Delete single """ & msg.Subject & """?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then   
   
 
 
 
 ' delete single msg  
    return True  
 
End If   
   
 
 
 
   
 
Return False   
   
 
 
 
   
 
End Function   
 
 
 

 

 

 

 

 

 

 

 




Greetings Falk

2 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Feb 2010, 03:13 PM
Hi Falk Wegener,

Thank you for writing. You can use custom grid behavior and override ProcessDeleteKey to include confirmation dialog. Please, consider the following code:

this.radGridView1.GridBehavior = new CustomGridBehavior();
  
public class CustomGridBehavior : BaseGridBehavior
{
  
    protected override bool ProcessDeleteKey(KeyEventArgs keys)
    {
            DialogResult dr = MessageBox.Show("Selected row(s) will be deleted! Are you sure?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                return base.ProcessDeleteKey(keys);
            }
        return true;
    }
}

I hope this helps. Do not hesitate to contact me again if you have any other questions.

All the best,
Martin Vasilev
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
Technik
Top achievements
Rank 1
answered on 04 Mar 2010, 04:10 PM
Hi Martin,
it works like a charm. Thank you.

Greetings
Falk
Tags
GridView
Asked by
Technik
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Technik
Top achievements
Rank 1
Share this question
or