AutoScroll NTreeView on Drag&Drop


Author
Message
Fabian Baptista
Fabian Baptista
Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)
Group: Forum Members
Posts: 18, Visits: 1
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!!!
Fabian Baptista
Fabian Baptista
Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)
Group: Forum Members
Posts: 18, Visits: 1
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
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search