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

DragDropManager OnDrop exception and fire twice

2 Answers 451 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Aldo
Top achievements
Rank 2
Aldo asked on 05 Feb 2014, 11:05 AM

public PanelAssociation(DateTime Date)
        {
            date = Date;
 
            InitializeComponent();
 
            Day.Text = date.ToShortDateString();
 
            DragDropManager.AddDropHandler(ListExtern, OnDrop);
            DragDropManager.AddDragOverHandler(ListExtern, OnDragOver);
        }
 
        private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var draggedItem = ((DataObject)e.Data).GetData("DragData");
            var droppedItem = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>();
 
            PeopleModel.PeopleDetail people = draggedItem as PeopleModel.PeopleDetail;
            OrderModel.OrderHead head = droppedItem.Item as OrderModel.OrderHead;
 
            //create program
            OrderModel.OrderService.CreateProgramByID(head, date, people.id);
        }
 
        private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DragData");
            var droppedItem = (e.OriginalSource as FrameworkElement).ParentOfType<RadTreeViewItem>();
 
            //remove all selections
            (sender as RadTreeView).SelectedItem = null;
 
            //select just droppeditem
            if (draggedItem is PeopleModel.PeopleDetail)
            {
                droppedItem.IsSelected = true;
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }
            e.Handled = true;
        }
Hi, i have a simple RadListBox to RadTreeView drag and drop, if i run, the event onDrop is called twice, if i debug, at the end of first ondrop return me an exception:
DragEventArgs.cs not found

i post my code:

2 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 10 Feb 2014, 07:11 AM
Hi Aldo,

From the code snippets you've sent it looks like you have attached DragOver and Drop handlers on the whole RadTreeView. In this case when you drop the listBoxItem on any RadTreeViewItem, Drop handler will be called for any visual element (RadTreeViewItem first, RadTreeView after that). In order to prevent this behavior you have to handle drop operation (set e.Handled = true in Drop handler). This way the event will not be raised up the visual tree.

As for the exception while debugging, is it really an exception or you are using F10 key and Visual Studio is searching for the next operation, which is in DragEventArgs.cs file (part of our code)? If it is exception, could you send a sample project reproducing the behavior as based on the current one we were unable to reproduce it.

Hope this helps. Feel free to contact us in case you have any problems or concerns.

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Minita
Top achievements
Rank 1
Veteran
answered on 03 Jul 2020, 04:42 AM
Handling event is the trick! It was very helpful! Thanks Rosen Vladimirov.
Tags
DragAndDrop
Asked by
Aldo
Top achievements
Rank 2
Answers by
Rosen Vladimirov
Telerik team
Minita
Top achievements
Rank 1
Veteran
Share this question
or