How to determine whether the source node is a child node of the target node or a brother node, devexpresstreelist

Source: Internet
Author: User

How to determine whether the source node is a child node of the target node or a brother node, devexpresstreelist

Purpose: only the same level of drag is allowed.

Two judgments:

1. If the parent node of the original node (assumed as: S) is not equal to the parent node of the target node (assumed as: T), it is moved across levels, that is, non-hierarchical movement. This is easy to judge.

2. S and T are at the same level, but S is moved to the lower level of T. In this scenario, S and T's parent nodes are consistent during the moving process, and they cannot determine whether to move across levels, so what should we do?

Solution 1: In the afterDrop event, determine whether the parent node is consistent. Because the movement has been completed, the parent node changes, and then restores the node back based on the judgment result. This approach is quite low.

Solution 2: During the movement process, determine the location where S is moved to T node: Before T node, after T node, and under T node. If it is moved to T node, move is prohibited.

The following describes how to determine solution 2:

 

/// <Summary> /// obtain the direction during the dragging process /// </summary> /// <param name = "sender"> </param> // <param name = "e"> </param> // <returns> </returns> private DragInsertPosition AjustDirection (object sender, dragEventArgs e) {TreeListNode dragNode, targetNode; TreeList tl = sender as TreeList; Point p = tl. pointToClient (new Point (e. x, e. y); dragNode = e. data. getData (typeof (TreeListNode) as TreeListNode; TreeListHitInfo hit = tl. calcHitInfo (p); PropertyInfo pi = typeof (TreeList ). getProperty ("Handler", BindingFlags. instance | BindingFlags. nonPublic); TreeListHandler handler = (TreeListHandler) pi. getValue (tl, null); return handler. stateData. dragInfo. dragInsertPosition ;}
Private void treeListNav_DragOver (object sender, DragEventArgs e) {TreeListNode dragNode = e. data. getData (typeof (TreeListNode) as TreeListNode; System. diagnostics. debug. writeLine ("Over:" + e. effect); TreeListNode targetNode; Point p = treeListNav. pointToClient (MousePosition); targetNode = treeListNav. calcHitInfo (p ). node; if (targetNode = null) {return;} FileContent tagParent = null; // parent data after dragging If (targetNode. ParentNode! = Null) {tagParent = this. treeListNav. GetRow (targetNode. ParentNode. Id) as FileContent;} if (sourceParent! = TagParent) // cross-level drag {// MessageHelper. ShowHit ("can only be dragged at the same level, but not successfully moved. "); E. effect = DragDropEffects. none; return;} // move to if (AjustDirection (sender, e) = DragInsertPosition. asChild) {e. effect = DragDropEffects. none; return;} if (e. effect = DragDropEffects. link) {// MessageHelper. showHit ("cannot be moved to a subset. "); E. Effect = DragDropEffects. None ;}}

This enumeration determines the direction of movement:

namespace DevExpress.XtraTreeList{    public enum DragInsertPosition    {        None = 0,        AsChild = 1,        Before = 2,        After = 3    }}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.