ConvertDraggedData with GridView & ListView

3 posts, 1 answers
  1. Kieron
    Kieron avatar
    16 posts
    Member since:
    Nov 2013

    Posted 04 May Link to this post

    So I'm trying to get the ScheduleView to allow a gridview and a listbox drop appointments (ScheduleItems) on it - and I can't seem to get the ConvertDraggedData to work properly because the ListBox sends through an IEnumerable<IOccurrence> and my GridView sends the raw item through (ScheduleItem).

    So I rolled my own GridViewDragDropBehaviour class (as there isn't one built in for the GridView) and on the OnDragInitialize event, I'm using IDragPayload.SetData() to set the data to be the raw (ScheduleItem) item.  The ListBox is using the built in ListBoxDragDropBehaviour class.

    This is my ConvertDraggedData code:

    public override IEnumerable<IOccurrence> ConvertDraggedData(object data)
    {
    if (DataObjectHelper.GetDataPresent(data, typeof(ScheduleItem), false))
    {
        return ((IEnumerable)DataObjectHelper.GetData(data, typeof(ScheduleItem), false)).OfType<IOccurrence>();
    }
    return base.ConvertDraggedData(data);
    }

     

    Obviously when items are dragged from the GridView the specified cast to IEnumerable doesn't work - but it works fine from the ListBox.  How do I tweak the code so that it will work for both controls?

  2. Answer
    Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 05 May Link to this post

    Hi Kieron,

    Attached you could find a sample project that demonstrates how you could implement the desired by you functionality between RadScheduleView, RadGridView  and RadListBox- to drag and drop appointments from the GridView and ListBox to RadScheduleView (check the implementation of ConvertDraggedData).

    Also, on the following link you could find a detailed information how that functionality between RadScheduleView and RadListBox is implemented:
    http://docs.telerik.com/devtools/wpf/controls/dragdropmanager/behaviors/listboxandscheduleview

    Notice that this is just an initial implementation and you might need to improve it.

    We hope this will help you.

    Regards,
    Nasko
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kieron
    Kieron avatar
    16 posts
    Member since:
    Nov 2013

    Posted 06 May in reply to Nasko Link to this post

    Ah brilliant, it was that simple - I was getting hung up on passing through the datatype rather than the name in GetDataPresent!  Thanks a lot.
Back to Top