8 Answers, 1 is accepted
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
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 >>
Can I have VB code instead since I'm using it?
Thanks
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_DragDropEnd SubPrivate 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 IfEnd SubPrivate Sub radPageView2_DragEnter(sender As Object, e As DragEventArgs) e.Effect = DragDropEffects.MoveEnd SubPrivate 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 IfEnd SubFor any further questions, do not hesitate to contact us.
Regards,
George
Telerik
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 >>
Thanks for the code! :)
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.
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
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?
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:
- https://msdn.microsoft.com/en-us/library/96826a87.aspx
- http://stackoverflow.com/questions/36232369/c-sharp-winforms-drag-custom-control-to-another-form
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
