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

Drag to specific slot from external source

6 Answers 169 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Ryszard
Top achievements
Rank 1
Ryszard asked on 30 Nov 2010, 05:07 PM
I'm trying to implement dragging from a ListBox onto a ScheduleView, using DragAndDropManager.  I'm as far as the DropInfo handler on the view where the ScheduleView resides running, and am successfully getting the information that I want from the ListBox.  What I can't figure out is how to find out which slot I am trying to drop into.  DragDropEventArgs.Options.CurrentDragPoint would seem a promising way to this information, and the demos show how to so this for the old Scheduler control, but ScheduleView appears to operate differently.  The only other piece of information that I can find suggests that DefaultDragDropBehavior.ValidateExternalDrag "could be used to add the appointments from external source".

Is there a simple example available demonstrating how to drag from an external non-ScheduleView source onto a specific slot within a ScheduldeView in order to create a new appointment based on the dragged-in object?  If not, would it at least be possible to provide some pointers as to how I can achieve this?


Thanks
Ryszard

6 Answers, 1 is accepted

Sort by
0
Ryszard
Top achievements
Rank 1
answered on 01 Dec 2010, 09:02 PM
I eventually unearthed RadDragAndDropExtensions.GetNewTime() which looks as though it should do what I'm after.  However, when I call it from DropInfo handler it throws a NullReferenceException:

        private void OnDropInfo(object sender, DragDropEventArgs e)
        {
            if (e.Options.Status == DragStatus.DropComplete)
            {
                DateTime time = RadDragAndDropExtensions.GetNewTime(e);

                MessageBox.Show("Dropping " + e.Options.Payload + " on " + time.ToString());
            }
        }

The DragDropEventArgs (e) is not null, so I guess that GetNewTime() doesn't like something about one of its members.

The DragQuery handler is lifted straight from http://www.telerik.com/help/silverlight/raddraganddrop-items-onto-radscheduler.html:

     private void OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            if (e.Options.Status == DragStatus.DragQuery)
            {
                var draggedItem = e.Options.Source;
                e.QueryResult = true;
                e.Handled = true;

                // Create Drag and Arrow Cue
                ContentControl dragCue = new ContentControl();
                dragCue.Content = draggedItem.DataContext;
                e.Options.DragCue = dragCue;
                e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();

                // Set the payload (this is the item that is currently dragged)
                e.Options.Payload = draggedItem.DataContext;
            }

            if (e.Options.Status == DragStatus.DropSourceQuery)
            {
                e.QueryResult = true;
                e.Handled = true;
            }
        }

Can anybody see what I'm missing that causes RadDragAndDropExtensions.GetNewTime() to throw the NullReferenceException?


Thanks
Ryszard
0
Ryszard
Top achievements
Rank 1
answered on 01 Dec 2010, 09:25 PM
Also get exactly the same result when I try to drag and drop an appointment within the ScheduleView, which I find suspicious.  The exception details pinpoint the location of the exception:

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=Telerik.Windows.Controls.ScheduleView
  StackTrace:
       at Telerik.Windows.Controls.RadDragAndDropExtensions.GetNewTime(DragDropEventArgs e) in c:\Dev3\branches\2010.Q3.Release\Controls\ScheduleView\ScheduleView\Helpers\DragDropExtensions.cs:line 48

Again, any thoughts on this greatly appreciated, 'cos I'm getting a headache :~)


Thanks
Ryszard
0
Rosi
Telerik team
answered on 06 Dec 2010, 05:05 PM
Hi Ryszard,

Please find the attached project illustrating how to implement drag from a listbox to RadScheduleView.

Do not hesitate to contact us if you need more help.

Greetings,
Rosi
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Ryszard
Top achievements
Rank 1
answered on 07 Dec 2010, 02:27 PM
Wow, that looks like a very comprehensive example that covers pretty much everything that I am trying to achieve.  Thank you very much for your help.


Ryszard
0
Rod Yager
Top achievements
Rank 1
answered on 14 Dec 2010, 06:49 AM

I found this sample helpful as well. One thing I haven't been able to figure out is how to get the destination value like resource assigned when dropping. My example is almost exactly like the Schedule View demo of Custom Styles> Group Header Styles. I want to know what resource has been assigned so that I can do some updating in the DB.

SchedulerDragDropPayload payload = e.Options.Payload as SchedulerDragDropPayload;
            if (e.Options.Status == DragStatus.DropComplete && payload != null && e.Options.Source is MetrixListView)
            {
                IList selectedItems = payload.DragDropState.Data as IList;
                foreach (DataRowView drv in selectedItems)
                {
                    //Need to know the destination resource that this payload has been dropped on?
                }
            }

Thanks for any help provided!
Rod
0
Rosi
Telerik team
answered on 16 Dec 2010, 03:40 PM
Hi Rod Yager,

You can access the resources of the destination slot by the following way;

SchedulerDragDropPayload payload = e.Options.Payload as SchedulerDragDropPayload
payload .DragDropState.DestinationSlots.First().Resources
;

Kind regards,
Rosi
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
ScheduleView
Asked by
Ryszard
Top achievements
Rank 1
Answers by
Ryszard
Top achievements
Rank 1
Rosi
Telerik team
Rod Yager
Top achievements
Rank 1
Share this question
or