Drag and Drop Appointments from a DataGrid to RadSchedualview

5 posts, 0 answers
  1. Sammy
    Sammy avatar
    26 posts
    Member since:
    Aug 2012

    Posted 27 Aug 2012 Link to this post

    Trying to figure out how to do this.

    I have a list of appointments in a regular silverlight DataGrid. I would like to Drag and Drop an appointment, from the DataGrid, to the RadScheduleView. Basically, this would be a copy of the appointment, but at a different time (for background info: the DataGrid shows the most popular appointments for that user, and it would allow them to drag and drop new appointments to the RadScheduleView. This would be a super quick and easy way to create appointments, without typing a single character)

    I started to implement this, using the example:
    http://demos.telerik.com/silverlight/#ScheduleView/DragDrop

    But this shows the source as a RadListBox. I'm not quite understanding how I can change my source from a RadListBox to a regular DataGrid. If I have too, I would change my DataGrid to a RadGrid.

    Any suggestions?

    Thanks!
  2. Sammy
    Sammy avatar
    26 posts
    Member since:
    Aug 2012

    Posted 28 Aug 2012 Link to this post

    fyi...I switched to a RadGridView and got this working.

  3. DevCraft banner
  4. Sammy
    Sammy avatar
    26 posts
    Member since:
    Aug 2012

    Posted 29 Aug 2012 Link to this post

    Ok, I have the drag and drop working. However, what is happening, is a Row is actually being removed from the RadGridview. Instead, I would like to implement a copy. Where the appointment is copied from the RadGridView to the ScheduleView.

    What events/where should I be looking at to perform a copy, rather than removing rows?

    Thanks!
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Aug 2012 Link to this post

    Hello,

     As I understand you have implemented drag from a GridView with the help of the DragDropManager. Your problem is that when you drop the dragged GridViewRow to a destination, then it is removed from the GridView. I suppose that you remove the row once it has been dropped. I am not sure what is your exact implementation but may I ask you to check what code you execute when the DragDropCompleted event is raised? Do you remove the dragged item?

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Sammy
    Sammy avatar
    26 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2012 Link to this post

    Hi Didie,
    Thanks for taking the time to reply.  This is the 1st time I've implemented DragDrop with Telerik controls, so I don't quite understand how it works. Basically, I found some code on your website, and used that. Somehow it all automagically worked. I just don't understand how.  Here is my Xaml code:


          <telerik:RadGridView ...>
                <telerik:RadGridView.RowStyle>
                    <Style TargetType="telerik:GridViewRow">
                        <Setter Property="drag:DragDropManager.AllowDrag" Value="True"  />
                    </Style>
                </telerik:RadGridView.RowStyle>
    <
    gridDrag:GridViewDragDrop.Behavior>
          <gridDrag:GridViewDragDropBehavior  />
      </gridDrag:GridViewDragDrop.Behavior>
     
      <gridDrag:GridViewDragDrop.DataConverter>
          <local:DataConverterAppointments />
      </gridDrag:GridViewDragDrop.DataConverter>
     
      <gridDrag:GridViewDragDrop.DragVisualProvider>
          <dragDropBehaviors:ScreenshotDragVisualProvider />
      </gridDrag:GridViewDragDrop.DragVisualProvider>
          </telerik:RadGridView>

    Here are the classes:

    public class GridViewDragDrop : DragDrop<GridViewDragDropHelper, GridViewDragDropBehavior, Telerik.Windows.DragDrop.Behaviors.DragDropState>
    {
     
    }
     
    public class GridViewDragDropBehavior : DragDropBehavior<Telerik.Windows.DragDrop.Behaviors.DragDropState>
    {
     
    }
     
    public class GridViewDragDropHelper : DragDropHelper<GridViewDragDropBehavior, Telerik.Windows.DragDrop.Behaviors.DragDropState>
    {
     
        protected override IList GetItemsSource(FrameworkElement control)
        {
            var gridView = control as RadGridView;
     
            return gridView == null ? null : (IList)gridView.ItemsSource;
        }
     
        protected override DependencyObject GetContainerFromItem(FrameworkElement control, object item)
        {
            return ((RadGridView)control).ItemContainerGenerator.ContainerFromItem(item);
        }
     
        protected override IEnumerable<object> GetDraggedItems(FrameworkElement element)
        {
            var gridView = element.ParentOfType<RadGridView>();
            if (gridView != null)
            {
                var selectedItems = gridView.SelectedItems;
                var item = element.DataContext;
     
                if (!selectedItems.Contains(item))
                {
                    if (gridView.SelectionMode == System.Windows.Controls.SelectionMode.Single)
                    {
                        gridView.SelectedItem = item;
                    }
                    else
                    {
                        selectedItems.Add(item);
                    }
                }
     
                return selectedItems.OfType<object>().ToList();
            }
            return Enumerable.Empty<object>();
        }
     
        protected override FrameworkElement FindDragSource(FrameworkElement element)
        {
            return element as RadGridView ?? element.ParentOfType<RadGridView>();
        }
     
        protected override FrameworkElement FindDraggedItem(FrameworkElement element)
        {
            return element as GridViewRow ?? element.ParentOfType<GridViewRow>();
        }
     
        protected override FrameworkElement FindDropItemsControl(FrameworkElement element, object data)
        {
            return element as RadGridView ?? element.ParentOfType<RadGridView>();
        }
     
        protected override FrameworkElement FindDropTarget(FrameworkElement element)
        {
            return element as RadGridView ?? element.ParentOfType<RadGridView>();
        }
    }

    There are 2 empty classes, and 1 that does some workl
    I don't quite understand how the row is being removed, or what event I need to tie into to copy from the RadGridView, rather than remove from it.

    Thanks for your time.



Back to Top
DevCraft banner