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

Exception about DragDrop event of the RadGridview & RadListBox

2 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 12 Aug 2008, 06:02 AM

hi, Telerik

I write the code below:

bool AddControlItem()
{
  RadListBoxItem itemRepair = new RadListBoxItem();
  itemRepair.MouseDown += new MouseEventHandler(itemRepair_MouseDown);
  lstControlItemList.Items.Add(itemRepair);
}

void itemRepair_MouseDown(object sender, MouseEventArgs e)
{
   RadListBoxItem lstItem = sender as RadListBoxItem;
   if (lstItem == null) { return; }

   lstControlItemList.DoDragDrop(lstItem, DragDropEffects.Copy | DragDropEffects.Move);
}

And target-object DragDrop method :

        void Gridview1_DragDrop(object sender, DragEventArgs e)
        {
            RadListBoxItem lstItem = e.Data.GetData(typeof(RadListBoxItem)) as RadListBoxItem;
            if (lstItem == null) { return; }

            GridViewRowInfo rowInfo = Gridview1.Rows.AddNew();
            rowInfo.Cells["RepairNO"].Value = lstItem.Value.ToString();

     lstControlItemList.Items.Remove(lstItem);
        }

Then throw exception:

System.InvalidOperationException not process
  Message="Argument not found in the list box items collection"
  Source="Telerik.WinControls.UI"
  StackTrace:
       Telerik.WinControls.UI.RadListBoxElement.selectedItems_CollectionChanged(Object sender, RadListBoxItemCollectionChangedEventArgs e)
       Telerik.WinControls.UI.RadListBoxItemCollection.OnCollectionChanged(RadListBoxItemCollectionChangedEventArgs e)
       Telerik.WinControls.UI.RadListBoxItemCollection.OnInsertComplete(Int32 index, Object value)
       System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
       Telerik.WinControls.UI.RadListBoxElement.SetSelectedIndex(RadItem item)
       Telerik.WinControls.UI.RadListBoxElement.listBoxItem_MouseDown(Object sender, MouseEventArgs e)
       System.Windows.Forms.MouseEventHandler.Invoke(Object sender, MouseEventArgs e)
       Telerik.WinControls.RadElement.OnMouseDown(MouseEventArgs e)
       Telerik.WinControls.RadItem.OnMouseDown(MouseEventArgs e)
       Telerik.WinControls.RadElement.OnCLREventsRise(RoutedEventArgs args)
       Telerik.WinControls.RadElement.OnBubbleEvent(RadElement sender, RoutedEventArgs args)
       Telerik.WinControls.RadItem.OnBubbleEvent(RadElement sender, RoutedEventArgs args)
       Telerik.WinControls.RadElement.RaiseBubbleEvent(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.ComponentInputBehavior.OnMouseDown(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)
       System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

I can not handled the exception. How can swallow that?

using Q1 2008 version.

KEN

2 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 14 Aug 2008, 08:23 AM
Hi SIN YI,

I don't know your project in details, but my assumption is that you execute entirely the drag&drop operation on item's MouseDown event. This includes the removing listbox item from the Items collection. However, after firing item's MouseDown event, RadListBox performs some additional work with the same item (this is the behavior in the Q1 2008 release) which causes the exception. I suppose that if you invoke drag&drop operation on item's MouseUp event it'll be ok. Another solution is to upgrade your version to Q2 2008 where the problem would not exist since we've changed the behavior to set RadListBox.SelectedIndex not on MouseDown but on MouseUp event.

Please try one of these solutions and if the problem still persist it'll be better if you send us a sample application that reproduces the error so we could find the most proper solution.

Kind regards,
Georgi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ken
Top achievements
Rank 1
answered on 14 Aug 2008, 09:10 AM
Hi, Georgi:

I try invoke drag&drop operation on item's MouseUp event, it's ok,

but user operate will be hard, because MouseUp event not generally used mode.

So, I try another design mode. And I'll upgrade version to Q2 2008 when finish my current job.

Thank for your solution appreciatively!

Best regards

KEN



Tags
GridView
Asked by
Ken
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Ken
Top achievements
Rank 1
Share this question
or