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

ConvertDraggedData with GridView & ListView

2 Answers 92 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Kieron
Top achievements
Rank 1
Kieron asked on 04 May 2016, 02:13 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 05 May 2016, 02:06 PM
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.
0
Kieron
Top achievements
Rank 1
answered on 06 May 2016, 08:11 AM
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.
Tags
ScheduleView
Asked by
Kieron
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Kieron
Top achievements
Rank 1
Share this question
or