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

RowDeleting e.cancel cause crash

3 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 14 Feb 2008, 07:22 PM
Hi,
    if I try to cancel a delete action in the RadGridView, I got a execption error.

The problem appear in the Option dialog of the radRibbon. In this dialog I got a radGridview, if something are deleted, I check if I can delete it. If not a set the e.cancel = true. If e.cancel=true the system give me this error:

System.ArgumentOutOfRangeException was unhandled  
  Message="L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection. Nom du paramètre : index" 
  ParamName="index" 
  Source="mscorlib" 
  StackTrace:  
       à System.Collections.ArrayList.get_Item(Int32 index)    à Telerik.WinControls.UI.GridViewInfo.DeleteRow(GridViewDataRowInfo[] rows)    à Telerik.WinControls.UI.GridTableBodyElement.ProcessCmdKey(Keys keyData)    à Telerik.WinControls.UI.RadGridView.ProcessCmdKey(Message& msg, Keys keyData)    à System.Windows.Forms.Control.PreProcessMessage(Message& msg)    à System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)    à System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)    à System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)    à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)    à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    à System.Windows.Forms.Form.ShowDialog(IWin32Window owner)    à System.Windows.Forms.Form.ShowDialog()    à Progest.ProgestVB.frmMain.RadRibbonBar1_OptionsButton_Click(Object sender, EventArgs e) dans C:\DotNet_WS\Progest\Dev\Progest\Forms\frmMain.vb:ligne 191    à System.EventHandler.Invoke(Object sender, EventArgs e)    à Telerik.WinControls.RadItem.OnClick(EventArgs e)    à Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)    à Telerik.WinControls.RadItem.DoClick(EventArgs e)    à Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)    à Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)    à Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)    à Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)    à Telerik.WinControls.RadElement.DoMouseDown(MouseEventArgs e)    à Telerik.WinControls.RadControl.OnMouseDown(MouseEventArgs e)    à System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)    à System.Windows.Forms.Control.WndProc(Message& m)    à System.Windows.Forms.ScrollableControl.WndProc(Message& m)    à Telerik.WinControls.RadControl.WndProc(Message& m)    à Telerik.WinControls.UI.RadPopupControl.WndProc(Message& m)    à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)    à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)    à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    à System.Windows.Forms.Application.Run(Form mainForm)    à Progest.ProgestVB.Program.Main(String[] args) dans C:\DotNet_WS\Progest\Dev\Progest\Main.vb:ligne 17    à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    à System.Threading.ThreadHelper.ThreadStart_Context(Object state)    à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    à System.Threading.ThreadHelper.ThreadStart()  
  InnerException:  

I try to use e.cancel=true in the validating event and all work good. I have trouble only in the deleting event.

The exception are on the line:  opt.ShowDialog()

        Private Sub RadRibbonBar1_OptionsButton_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles RadRibbonBar1.OptionsButton.Click  
            Dim Opt As New dlgOptions  
            Opt.ShowDialog()  
            Opt.Dispose()  
        End Sub 

here the deleting function:
        Private Sub RadGridSegments_RowDeleting(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.RowDeletingEventArgs) Handles RadGridSegments.RowDeleting  
            If oSegment.PeutEffacer(e.Row.Cells("ID").Value) = False Then 
                MessageBox.Show(RM.GetString("dlgConfig_EffSegment"), "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)  
                e.Cancel = True 
            End If 
        End Sub 

any suggestion?

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Feb 2008, 09:25 AM
Hello Pierre,

Thank you for writing us.

We addressed this issue in our latest release the Q3 2007 SP1. You can download it directly from your client account.

Let us know if you need further assistance.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
joseph_korn
Top achievements
Rank 1
answered on 16 May 2008, 05:57 PM
I understand that this bug was fixed in the Q3 2007 SP1 release, but I seem to be having the same problems with Q1 2008.. Can anyone verify that this is in fact working? I have a command cell in my gridview which I use as a delete button.. When I click delete, I want a msgbox popup to ask, 'Are you sure you want to delete this item?', and if no is clicked, then I want to cancel the delete.. here is a sample of my code:

    Private Sub grdTasks_CommandCellClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdTasks.CommandCellClick 
        Dim gcce As GridCommandCellElement = TryCast(sender, GridCommandCellElement) 
        Me.grdTasks.Rows.Remove(gcce.RowElement.RowInfo) 
    End Sub 
 
    Private Sub grdTasks_RowDeleting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowDeletingEventArgs) Handles grdTasks.RowDeleting 
        e.Cancel = Not MessageBox.Show("Are you sure you want to remove the item '" & e.Row.Cells("itemname").Value & "' from the list?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes 
    End Sub 

If I click 'yes' the row is deleted fine, but when I click 'no' I get the error:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

I get the same behavior when hitting the delete key on the keyboard, and right-clicking and choosing 'Delete Row'..

Any ideas?
0
Jack
Telerik team
answered on 17 May 2008, 03:35 PM
Hi Joseph,

Thank you for contacting us.

Yes, I confirm that this issue has been fixed in our Q1 2008 release, where the RowDeleting event is deprecated. You should use the RowsChanging event instead. Take a look at the code snippet below:

void radGridView1_RowsChanging(object sender, GridViewCollectionChangingEventArgs e) 
    if (e.Action == NotifyCollectionChangedAction.Remove) 
    { 
        GridViewRowInfo row = (GridViewRowInfo)e.OldItems[0]; 
        e.Cancel = !(MessageBox.Show("Are you sure you want to remove the item '" + row.Cells["Name"].Value + "' from the list?""Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes); 
    } 


I hope this helps. Do not hesitate to write me, if you have other questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Jack
Telerik team
joseph_korn
Top achievements
Rank 1
Share this question
or