Detect day on drag/drop from RadGridView

2 posts, 0 answers
  1. Elsa
    Elsa avatar
    1 posts
    Member since:
    Apr 2014

    Posted 29 Apr 2014 Link to this post

    Greetings.

    I'm experimenting with the latest demo version and running into an issue.  Mind you, this seems like an edge case based on what I've read from others, but hopefully you can guide me.

    I have an unbound RadGridView.  It's unbound because I need to support drag/drop resorting within itself, simple inline editing and drag/drop to a RadCalendar.  All of this is functioning well  (I made extensive use of various how-tos on drag/drop from RadGridViews).

    However, when I drag a row from the RadGridView to the RadCalendar, I'm unable to detect what day I've dragged the row onto.  This would be trivial if I were using the drag/drop events of the Calendar itself, but I'm not.  I'm using the Drag/Drop services I've declared as part of my extended RadGridView (similar to the documentation here:  http://blogs.telerik.com/winformsteam/posts/13-05-15/extending-radgridview-to-enable-row-drag-and-drop-functionality )

    My drop event looks like this...
     
    private void dragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
           {
               Console.WriteLine(e.HitTarget);
               var el = e.HitTarget as RadCalendarElement;
               if (el != null)
               {
                   GridDataRowElement draggedRow = ((SnapshotDragItem)e.DragInstance).Item as GridDataRowElement;
     
                   if (draggedRow != null)
                   {
                       int TaskID = (int)draggedRow.Data.Cells["TaskID"].Value;
                       // determine the date we dragged to, and update the task.
                       return;
                   }
               }

    How can I figure out which day I dropped the row onto?  I don't seem to be able to get anything out of RadCalendarElement, nor can I find a relevant CalendarCellElement.  Help!  :)

    Thanks,
    Elsa


  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 01 May 2014 Link to this post

    Hi Elsa,

    Thank you for writing.

    In this case you can recreate your PreviewDragDrop event handler to look like the following one:
    void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
    {
        RadCalendarElement el = e.HitTarget as RadCalendarElement;
     
        if (el != null)
        {
            GridDataRowElement dragedRow = ((SnapshotDragItem)e.DragInstance).Item as GridDataRowElement;
             
            if (dragedRow != null)
            {
                var date = el.ElementTree.GetElementAtPoint(e.DropLocation);
                el.Calendar.FocusedDate = DateTime.Parse(date.ToString());
            }
        }
    }

    The key point is the using of the GetElementAtPoint method which is used for the exact date element retrieval.

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top