We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to perform the node drag drop between an XPToolBar and TreeViewAdv?

Platform: WinForms |
Control: XPToolbar |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

Please refer the following steps to be performed to achieve this:

  • Place the TreeViewAdv and XPToolBar on the form.
  • Add nodes to the TreeViewAdv.
  • Set the AllowDrop property as True of the XPToolBar.
  • Handle the TreeViewAdv MouseDown event to access the node which is going to drag.
  • Handle the DragDrop and DragEnter events of XPToolBar to get the which is dragged from the TreeViewAdv.

Please refer the below code snippet which ilustrates this:

C#

private void xpToolBar1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)

{

Console.WriteLine("XPToolBar Drag Enter");

if (e.Data.GetDataPresent(typeof(TreeNodeAdv)))

e.Effect = DragDropEffects.Copy;

else

e.Effect = DragDropEffects.None;

}

private void xpToolBar1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)

{

Console.WriteLine("XPToolBar Drag Drop");

if (e.Data.GetDataPresent(typeof(TreeNodeAdv)))

{

TreeNodeAdv node = e.Data.GetData(typeof(TreeNodeAdv)) as TreeNodeAdv;

BarItem bitem = new BarItem(node.Text);

this.xpToolBar1.Items.Add(bitem);

}

}

private void treeViewAdv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

{

if (e.Button == MouseButtons.Left)

{

// get the point where the mouse was left clicked

Point p = this.treeViewAdv1.PointToClient(Control.MousePosition);

// get the node at the left click point

TreeNodeAdv node = this.treeViewAdv1.PointToNode(p);

this.treeViewAdv1.SelectedNode = node;

this.treeViewAdv1.Refresh();

DoDragDrop(node, DragDropEffects.Copy);

}

}

VB

Private Sub XpToolBar1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles XpToolBar1.DragDrop

Console.WriteLine("XPToolBar Drag Drop")

If e.Data.GetDataPresent(GetType(TreeNodeAdv)) Then

Dim node As TreeNodeAdv = CType(IIf(TypeOf e.Data.GetData(GetType(TreeNodeAdv)) Is TreeNodeAdv, e.Data.GetData(GetType(TreeNodeAdv)), Nothing), TreeNodeAdv)

Dim bitem As BarItem = New BarItem(node.Text)

Me.XpToolBar1.Items.Add(bitem)

End If

End Sub

Private Sub XpToolBar1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles XpToolBar1.DragEnter

Console.WriteLine("XPToolBar Drag Enter")

If e.Data.GetDataPresent(GetType(TreeNodeAdv)) Then

e.Effect = DragDropEffects.Copy

Else

e.Effect = DragDropEffects.None

End If

End Sub

Private Sub TreeViewAdv1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeViewAdv1.MouseDown

If e.Button = Windows.Forms.MouseButtons.Left Then

' get the point where the mouse was left clicked

Dim p As Point = Me.TreeViewAdv1.PointToClient(Control.MousePosition)

' get the node at the left click point

Dim node As TreeNodeAdv = Me.TreeViewAdv1.PointToNode(p)

Me.TreeViewAdv1.SelectedNode = node

Me.TreeViewAdv1.Refresh()

DoDragDrop(node, DragDropEffects.Copy)

End If

End Sub

Sample:

http://help.syncfusion.com/support/samples/KB/Tools.Windows/TDragDrop/DragDrop.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon