Hi Jon,
The XPToolBar’s DragDrop event does not get fired as expected (defect# 93) and this seems to be a shortcoming in our XPToolBar control. To workaround this issue, derive from our XPToolBar to create a CustomXPToolBar control (and a CustomDragDrop event handler) as shown below :
public class CustomXPToolBar : XPToolBar
{
public CustomXPToolBar () : base() {}
public event DragEventHandler CustomDragDrop;
protected override void OnDragDrop(System.Windows.Forms.DragEventArgs e)
{
if(this.CustomDragDrop != null)
this.CustomDragDrop(this, e);
}
}
Now handle the XPToolBar’s DragEnter, CustomDragDrop events and TreeViewAdv’s MouseDown events as shown below :
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_CustomDragDrop(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);
DoDragDrop(node, DragDropEffects.Copy);
}
}
The
complete sample illustrating the above is attached here. Please refer to it and let me know if you need further assistance.
Regards,
Guru Patwal
Syncfusion, Inc.