windowsforms-devexpress-dot-xtratreelist-dot-treelist-1eda369f.md
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.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
[DXCategory("DragDrop")]
public event CustomizeNewNodeFromOuterDataEventHandler CustomizeNewNodeFromOuterData
<DXCategory("DragDrop")>
Public Event CustomizeNewNodeFromOuterData As CustomizeNewNodeFromOuterDataEventHandler
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. |
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):
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.Important
Users cannot drag-and-drop the nodes between TreeList controls that are bound to the same data source.
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.
The following example demonstrates how to implement multiple node drag-and-drop between two TreeList controls:
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" },
};
}
}
Imports DevExpress.XtraTreeList
Public Sub New()
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
End Sub
Private Sub targetTreeList_CustomizeNewNodeFromOuterData(ByVal sender As Object, ByVal e As CustomizeNewNodeFromOuterDataEventArgs)
e.NewData("TaskName") = e.SourceNode("Name")
e.NewData("CreateDate") = Date.Now
End Sub
' Data objects.
Public Class PlannedTask
Public Property ID() As Integer
Public Property ParentID() As Integer
Public Property TaskName() As String
Public Property CreateDate() As Date
= Date.Now
public Boolean Finished {get;set;}
= False
public static List(Of PlannedTask) Init()
Return New List(Of PlannedTask)() From {
New PlannedTask() With {.ID = 0, .ParentID = 0, .TaskName = "Planned Task A"}
}
End Class
public class Task
public Integer ID {get;set;}
public Integer ParentID {get;set;}
public String Name {get;set;}
public static List(Of Task) Init()
Return New List(Of Task)() From {
New Task() With {.ID = 0, .ParentID = 0, .Name = "Task 1"},
New Task() With {.ID = 1, .ParentID = 0, .Name = "Task 2"},
New Task() With {.ID = 2, .ParentID = 1, .Name = "Task 3"},
New Task() With {.ID = 3, .ParentID = 1, .Name = "Task 4"},
New Task() With {.ID = 4, .ParentID = 1, .Name = "Task 5"}
}
See Also