Nevron Forum

AutoScroll NTreeView on Drag&Drop

https://www.nevron.com/Forum/Topic3427.aspx

By Fabian Baptista 1 - Monday, April 26, 2010

Hi, I'have my own NTreeView, and I'm allowing to Drag & Drop nodes.

The problem, is that when I drag a node, I want to move to a invisible node (invisible because the tree is scrolled).
I need autoscroll it.

How can I do this? This is very common in trees.
Can I add some code to scroll the tree in DragOver event?

Thanks!!!
By Fabian Baptista 1 - Monday, April 26, 2010

Solution c#:

private void DragOver(object sender, DragEventArgs e)
{
DragScroll(sender, e);

// Do Drag Over Logic
}


[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam,
int lParam);

// Implement an "autoscroll" routine for drag
// and drop. If the drag cursor moves to the bottom
// or top of the treeview, call the Windows API
// SendMessage function to scroll up or down automatically.
private void DragScroll(
object sender,
DragEventArgs e)
{
// Set a constant to define the autoscroll region
const Single scrollRegion = 20;

// See where the cursor is
Point pt = ProjectTV.PointToClient(Cursor.Position);

// See if we need to scroll up or down
if ((pt.Y + scrollRegion) > ProjectTV.Height)
{
// Call the API to scroll down
SendMessage(ProjectTV.Handle, (int)277, (int)1, 0);
}
else if (pt.Y < (ProjectTV.Top + scrollRegion))
{
// Call thje API to scroll up
SendMessage(ProjectTV.Handle, (int)277, (int)0, 0);
}
}



source: http://www.fmsinc.com/free/NewTips/NET/NETtip21.asp