ASPxTreeList.ProcessDragNode Event

Fires after a node drag and drop operation has been completed.

Namespace: DevExpress.Web.ASPxTreeList

Assembly: DevExpress.Web.ASPxTreeList.v19.2.dll

Declaration

public event TreeListNodeDragEventHandler ProcessDragNode
Public Event ProcessDragNode As TreeListNodeDragEventHandler

Event Data

The ProcessDragNode event handler receives an argument of the TreeListNodeDragEventArgs type. The following properties provide information specific to this event.

Property Description
Cancel Gets or sets whether the operation performed on the processed node should be cancelled.
(Inherited from TreeListNodeCancelEventArgs)
Handled Gets or sets whether the drag and drop operation is handled.
NewParentNode Gets a node to whose child collection the target (dragged) node is being moved.
Node Gets the node currently being processed.
(Inherited from TreeListNodeEventArgs)

Remarks

The ProcessDragNode event is raised after a user has dropped a node, allowing you to perform server-side processing, if required, or cancel the operation.

The event parameter's TreeListNodeEventArgs.Node property returns the dragged node. The target node is returned by the TreeListNodeDragEventArgs.NewParentNode property.

Set the TreeListNodeDragEventArgs.Handled property to true if default processing isn't required. To cancel the operation, set the TreeListNodeCancelEventArgs.Cancel property to true.

To learn more, see Drag and Drop.

Examples

If the ASPxTreeList operates in Virtual Mode, you should manually process node drag and drop operations. To do this, you should handle the ASPxTreeList.ProcessDragNode event.

In this example, dragged nodes correspond to files and folders. The ASPxTreeList.ProcessDragNode event is handled to move required files to a new location. Finally, the ASPxTreeList.RefreshVirtualTree method is called to recreate the tree. Don't forget to turn off the default drag-and-drop processing by setting the event parameter's Handled property to true. Otherwise, an exception will be thrown.

using System.IO;
using System.Collections.Generic;
using DevExpress.Web.ASPxTreeList;

protected void ASPxTreeList1_ProcessDragNode(object sender, TreeListNodeDragEventArgs e) {
    MoveFileToNewFolder(e.Node["FileName"].ToString(), e.NewParentNode["FileName"].ToString());
    ASPxTreeList1.RefreshVirtualTree();
    e.Handled = true;
}

protected void ASPxTreeList1_VirtualModeCreateChildren(object sender,
TreeListVirtualModeCreateChildrenEventArgs e) {
    string path = e.NodeObject == null ? Page.MapPath("~/") : e.NodeObject.ToString();

    List<string> children = new List<string>();
    if (Directory.Exists(path)) {
        foreach (string name in Directory.GetDirectories(path)) {
            if (!IsSystemName(name))
                children.Add(name);
        }
        foreach (string name in Directory.GetFiles(path))
            if (!IsSystemName(name))
                children.Add(name);
    }
    e.Children = children;
}
protected void ASPxTreeList1_VirtualModeNodeCreating(object sender,
TreeListVirtualModeNodeCreatingEventArgs e) {
    string path = e.NodeObject.ToString();

    e.NodeKeyValue = GetNodeGuid(path);
    e.IsLeaf = !Directory.Exists(path);
    e.SetNodeValue("FileName", PopFileName(path));
}

#region Helpers
Guid GetNodeGuid(string path) {
    if (!Map.ContainsKey(path))
        Map[path] = Guid.NewGuid();
    return Map[path];
}
Dictionary<string, Guid> Map {
    get {
        const string key = "DX_PATH_GUID_MAP";
        if (Session[key] == null)
            Session[key] = new Dictionary<string, Guid>();
        return Session[key] as Dictionary<string, Guid>;
    }
}
string PopFileName(string path) {
    return path.Substring(1 + path.LastIndexOf("\\"));
}
bool IsSystemName(string name) {
    name = PopFileName(name).ToLower();
    return name.StartsWith("app_") || name == "bin"
        || name.EndsWith(".aspx.cs") || name.EndsWith(".aspx.vb");
}
#endregion
See Also