Skip to main content

TreeList.CustomizeNewNodeFromOuterData Event

Allows you to initialize a new node when a user drops the node from another TreeList control onto the current TreeList control.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

[DXCategory("DragDrop")]
public event CustomizeNewNodeFromOuterDataEventHandler CustomizeNewNodeFromOuterData

Event Data

The CustomizeNewNodeFromOuterData event's data class is CustomizeNewNodeFromOuterDataEventArgs. The following properties provide information specific to this event:

Property Description
DestinationNode Gets the node onto which (or relative to which) the CustomizeNewNodeFromOuterDataEventArgs.SourceNode is dropped.
DestinationNodes Gets the collection of sibling nodes relative to which the CustomizeNewNodeFromOuterDataEventArgs.SourceNode is dropped.
Handled Gets or sets whether you perform all the required actions manually and no default processing is required.
NewData Provides access to the dictionary that contains data to initialize a new node.
SourceNode Gets the node (from another TreeList control) being dragged.

Remarks

Enable Node Drag & Drop

Set the following settings (TreeList.OptionsDragAndDrop) to allow a user to move or copy/paste nodes between different TreeList controls (the user drags a node from the source TreeList and drops it onto the target TreeList):

  • Set the DragNodesMode property to Single or Multiple for both TreeList controls to allow users to drag and drop one or multiple nodes. Enable the MultiSelect option to enable multiple node selection.
  • Enable the AcceptOuterNodes option for the target (destination) TreeList control.
  • Enable the CanCloneNodesOnDrop option for the target TreeList control to allow a user to copy the node(s) from the source TreeList and insert the node(s) in the target TreeList. The user must hold down the CTRL or SHIFT key while dragging. If this option is disabled, the dragged node(s) will be removed from the source TreeList.
  • In bound mode, initialize the target TreeList’s KeyFieldName and ParentFieldName properties.

Important

Users cannot drag-and-drop the nodes between TreeList controls that are bound to the same data source.

Initialize a New Node

Handle the target TreeList’s CustomizeNewNodeFromOuterData event to initialize a new node. The TreeList raises this event when the user drops the node onto it. If the user drags multiple nodes, the TreeList raises the CustomizeNewNodeFromOuterData event for each node.

Use the e.NewData property to supply data (the key-value pairs) for a new node(s). The keys are strings that specify field names. If the source and target TreeList controls are bound to the same data field, a value in the key-value pair is set to a value from this data field. Otherwise, you need to initialize the key-value pairs manually.

If the e.Handled parameter is set to false, the target TreeList creates and initializes a node with data from the e.NewData dictionary. If the e.Handled parameter is set to true, the TreeList does not create the node. You should manually create and initialize the node.

Example

The following example demonstrates how to implement multiple node drag-and-drop between two TreeList controls:

Multiple Node Drag and Drop - WinForms TreeList

using DevExpress.XtraTreeList;

public Form1() {
    InitializeComponent();
    // Initializes the source TreeList control.
    sourceTreeList.DataSource = Task.Init();
    sourceTreeList.KeyFieldName = "ID";
    sourceTreeList.ParentFieldName = "ParentID";
    sourceTreeList.OptionsDragAndDrop.DragNodesMode = DragNodesMode.Multiple;
    sourceTreeList.OptionsSelection.MultiSelect = true;

    // Initializes the target (destination) TreeList control.
    targetTreeList.DataSource = PlannedTask.Init();
    targetTreeList.KeyFieldName = "ID";
    targetTreeList.ParentFieldName = "ParentID";
    targetTreeList.OptionsDragAndDrop.DragNodesMode = DragNodesMode.Multiple;
    targetTreeList.OptionsDragAndDrop.AcceptOuterNodes = true;
}
private void targetTreeList_CustomizeNewNodeFromOuterData(object sender, CustomizeNewNodeFromOuterDataEventArgs e) {
    e.NewData["TaskName"] = e.SourceNode["Name"];
    e.NewData["CreateDate"] = DateTime.Now;
}

// Data objects.
public class PlannedTask {
    public int ID { get; set; }
    public int ParentID { get; set; }
    public string TaskName { get; set; }
    public DateTime CreateDate { get; set; } = DateTime.Now;
    public bool Finished { get; set; } = false;
    static public List<PlannedTask> Init() {
        return new List<PlannedTask>() {
            new PlannedTask(){ ID = 0, ParentID = 0, TaskName = "Planned Task A" }
        };
    }
}
public class Task {
    public int ID { get; set; }
    public int ParentID { get; set; }
    public string Name { get; set; }
    static public List<Task> Init() {
        return new List<Task>() {
            new Task(){ID = 0, ParentID = 0, Name = "Task 1" },
            new Task(){ID = 1, ParentID = 0, Name = "Task 2" },
            new Task(){ID = 2, ParentID = 1, Name = "Task 3" },
            new Task(){ID = 3, ParentID = 1, Name = "Task 4" },
            new Task(){ID = 4, ParentID = 1, Name = "Task 5" },
        };
    }
}
See Also