DragDrop Between RadPageViews

9 posts, 0 answers
  1. Justin
    Justin avatar
    7 posts
    Member since:
    Jun 2013

    Posted 27 Jun 2013 Link to this post

    Hi

    Is it possible to drag and drop pages between two or more RadPageView controls? I used a RadSplitContainer to put two RadPageViews side by side, but can't seem to drag the pages between both of them.

    Thanks.
  2. George
    Admin
    George avatar
    500 posts

    Posted 28 Jun 2013 Link to this post

    Hi Justin,

    Thank you for writing.

    You can drag and drop pages from one page view to another and vice-versa using the OLE drag drop. Here is a sample:
    public Form1()
    {
        InitializeComponent();
     
        this.radPageView1.MouseDown += radPageView1_MouseDown;
        this.radPageView2.MouseDown += radPageView1_MouseDown;
     
        this.radPageView1.AllowDrop = true;
        this.radPageView2.AllowDrop = true;
     
        this.radPageView1.DragEnter += radPageView2_DragEnter;
        this.radPageView2.DragEnter += radPageView2_DragEnter;
     
        this.radPageView1.DragDrop += radPageView2_DragDrop;
        this.radPageView2.DragDrop += radPageView2_DragDrop;
    }
     
    private void radPageView2_DragDrop(object sender, DragEventArgs e)
    {
        RadPageView target = ((RadPageView)sender);           
        RadPageViewPage temp = (RadPageViewPage)e.Data.GetData(typeof(RadPageViewPage));
        RadPageView source = temp.Owner;
        if (target != source)
        {
            target.Pages.Add(temp);
        }
    }
     
    private void radPageView2_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Move;
    }
     
    private void radPageView1_MouseDown(object sender, MouseEventArgs e)
    {
        RadPageViewStripItem item = ((RadPageView)sender).ElementTree.GetElementAtPoint(e.Location) as RadPageViewStripItem;
     
        if (item != null)
        {
            ((RadPageView)sender).DoDragDrop(item.Page, DragDropEffects.Move);
        }
    }

    I hope this helps. Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Justin
    Justin avatar
    7 posts
    Member since:
    Jun 2013

    Posted 29 Jun 2013 Link to this post

    Hi, 

    Can I have VB code instead since I'm using it?

    Thanks
  5. George
    Admin
    George avatar
    500 posts

    Posted 01 Jul 2013 Link to this post

    Hi Justin,

    Thank you for writing back.

    Here is the code in Visual Basic as you asked.
    Public Sub New()
        InitializeComponent()
     
        Me.radPageView1.MouseDown += radPageView1_MouseDown
        Me.radPageView2.MouseDown += radPageView1_MouseDown
     
        Me.radPageView1.AllowDrop = True
        Me.radPageView2.AllowDrop = True
     
        Me.radPageView1.DragEnter += radPageView2_DragEnter
        Me.radPageView2.DragEnter += radPageView2_DragEnter
     
        Me.radPageView1.DragDrop += radPageView2_DragDrop
        Me.radPageView2.DragDrop += radPageView2_DragDrop
    End Sub
     
    Private Sub radPageView2_DragDrop(sender As Object, e As DragEventArgs)
        Dim target As RadPageView = DirectCast(sender, RadPageView)
        Dim temp As RadPageViewPage = DirectCast(e.Data.GetData(GetType(RadPageViewPage)), RadPageViewPage)
        Dim source As RadPageView = temp.Owner
        If target <> source Then
            target.Pages.Add(temp)
        End If
    End Sub
     
    Private Sub radPageView2_DragEnter(sender As Object, e As DragEventArgs)
        e.Effect = DragDropEffects.Move
    End Sub
     
    Private Sub radPageView1_MouseDown(sender As Object, e As MouseEventArgs)
        Dim item As RadPageViewStripItem = TryCast(DirectCast(sender, RadPageView).ElementTree.GetElementAtPoint(e.Location), RadPageViewStripItem)
     
        If item IsNot Nothing Then
            DirectCast(sender, RadPageView).DoDragDrop(item.Page, DragDropEffects.Move)
        End If
    End Sub

    For any further questions, do not hesitate to contact us.
     

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Justin
    Justin avatar
    7 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2013 Link to this post

    Hi again

    Thanks for the code! :)
  7. Krunal
    Krunal avatar
    4 posts
    Member since:
    Aug 2015

    Posted 14 Jun Link to this post

    With drag and drop pages between two or more RadPageView controls, drag(move) pages within RadPageView(below code) stop working.

    this.strip = this.radPageView1.ViewElement as RadPageViewStripElement; 
    this.strip.ItemDragMode = PageViewItemDragMode.Preview;

    Need to drag and drop between radPageView and within radPageView

    Thanks.

  8. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 15 Jun Link to this post

    Hi Krunal,

    Thank you for writing.

    The code snippet my colleague sent is working fine on my end. Could you please open up a support ticket and send us your project demonstrating what you are trying to accomplish?

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  9. Kasim
    Kasim avatar
    1 posts
    Member since:
    Feb 2016

    Posted 25 Aug Link to this post

    Hi Hristo,

    I am using UI for Window (Desktop application) with 2016 Q2 Telerik controls.

    I have RadPageViews in different combinations like:

    1. PageViews in different panels (Split/Collapsible).

    2. PageView within page view

    3. PageView in different RadForms

    4. Pages within same page view (ItemDragMode = PageViewItemDragMode.Preview).

    I want to have drag drop functionality between all above combinations (except for parent in the ElementTree the pageview cannot be moved within a child pageview). I tried the code snippet shared above but it's not working with me.

    In my case only thing that is working is pages within same pageview. When trying to do any other combination, either the application hangs or do nothing.

    Can you please share code sample with above combinations working?

  10. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 25 Aug Link to this post

    Hello Kasim,

    Thank you for writing.

    I am attaching a project utilizing the solution as suggested by my colleague. Please check how it runs on your end. It handles all of the mentioned scenarios assuming the controls are located in one form.

    Regarding your requirement for drag drop between forms please refer to the following resources: 
    I have also included a project handling the described scenarios including a simple example for dragging and dropping pages between two forms.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready