/// <summary> /// Descrides the Drop event of the RowDragDroController and handles the drop items from ListView /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RowDragDropController_Drop(object sender, Syncfusion.UI.Xaml.TreeGrid.TreeGridRowDropEventArgs e) { if (e.IsFromOutSideSource) { var item = e.Data.GetData("Nodes") as ObservableCollection <TreeViewNode>; var treeViewNode = item[0] as TreeViewNode; var record = treeViewNode.Content as PersonInfo; var dropPosition = e.DropPosition.ToString(); var newItem = new PersonInfo(); IList sourceCollection = null; if (e.TargetNode != null) { var rowIndex = AssociatedObject.treeGrid.ResolveToRowIndex(e.TargetNode.Item); int nodeIndex = (int)rowIndex; if (dropPosition != "None" && rowIndex != -1) { var treeNode = AssociatedObject.treeGrid.GetNodeAtRowIndex(rowIndex); if (treeNode == null) { return; } if (AssociatedObject.treeGrid.View is TreeGridNestedView) { var data = treeNode.Item; AssociatedObject.treeGrid.SelectionController.SuspendUpdates(); var itemIndex = -1; TreeNode parentNode = null; if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { parentNode = treeNode.ParentNode; newItem = new PersonInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, DOB = record.DOB, Children = record.Children }; } else if (dropPosition == "DropAsChild") { if (!treeNode.IsExpanded) { AssociatedObject.treeGrid.ExpandNode(treeNode); } parentNode = treeNode; newItem = new PersonInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, DOB = record.DOB, Children = record.Children }; } if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { if (treeNode.ParentNode != null) { var collection = AssociatedObject.treeGrid.View.GetPropertyAccessProvider().GetValue(treeNode.ParentNode.Item, AssociatedObject.treeGrid.ChildPropertyName) as IEnumerable; sourceCollection = GetSourceListCollection(collection); } else { sourceCollection = GetSourceListCollection(AssociatedObject.treeGrid.View.SourceCollection); } itemIndex = sourceCollection.IndexOf(data); if (dropPosition == "DropBelow") { itemIndex += 1; } } else if (dropPosition == "DropAsChild") { var collection = AssociatedObject.treeGrid.View.GetPropertyAccessProvider().GetValue(data, AssociatedObject.treeGrid.ChildPropertyName) as IEnumerable; sourceCollection = GetSourceListCollection(collection); if (sourceCollection == null) { var list = data.GetType().GetProperty(AssociatedObject.treeGrid.ChildPropertyName).PropertyType.CreateNew() as IList; if (list != null) { AssociatedObject.treeGrid.View.GetPropertyAccessProvider().SetValue(treeNode.Item, AssociatedObject.treeGrid.ChildPropertyName, list); sourceCollection = list; } } itemIndex = sourceCollection.Count; } sourceCollection.Insert(itemIndex, newItem); AssociatedObject.treeGrid.SelectionController.ResumeUpdates(); (AssociatedObject.treeGrid.SelectionController as TreeGridRowSelectionController).RefreshSelection(); } if (treeViewNode.Level == 0) { (AssociatedObject.treeView.ItemsSource as ObservableCollection <PersonInfo>).Remove(record as PersonInfo); } else { ((treeViewNode.ParentNode.Content as PersonInfo).Children as ObservableCollection <PersonInfo>).Remove(treeViewNode.Content as PersonInfo); } } } else { sourceCollection = GetSourceListCollection(AssociatedObject.treeGrid.View.SourceCollection); sourceCollection.Insert(0, record); (AssociatedObject.treeView.ItemsSource as ObservableCollection <PersonInfo>).Remove(record as PersonInfo); } } }
/// <summary> /// Descrides the Drop event of the RowDragDroController and handles the drop items from ListView /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RowDragDropController_Drop(object sender, Syncfusion.UI.Xaml.TreeGrid.TreeGridRowDropEventArgs e) { if (e.IsFromOutSideSource) { var item = e.Data.GetData("ListViewRecords") as ObservableCollection <object>; var record = item[0] as EmployeeInfo; var dropPosition = e.DropPosition.ToString(); var newItem = new EmployeeInfo(); var rowIndex = AssociatedObject.sfTreeGrid.ResolveToRowIndex(e.TargetNode.Item); int nodeIndex = (int)rowIndex; if (dropPosition != "None" && rowIndex != -1) { if (AssociatedObject.sfTreeGrid.View is TreeGridSelfRelationalView) { var treeNode = AssociatedObject.sfTreeGrid.GetNodeAtRowIndex(rowIndex); if (treeNode == null) { return; } var data = treeNode.Item; AssociatedObject.sfTreeGrid.SelectionController.SuspendUpdates(); var itemIndex = -1; TreeNode parentNode = null; if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { parentNode = treeNode.ParentNode; if (parentNode == null) { newItem = new EmployeeInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, Salary = record.Salary, Title = record.Title, ReportsTo = -1 } } ; else { var parentkey = parentNode.Item as EmployeeInfo; newItem = new EmployeeInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, Salary = record.Salary, Title = record.Title, ReportsTo = parentkey.ID }; } } else if (dropPosition == "DropAsChild") { if (!treeNode.IsExpanded) { AssociatedObject.sfTreeGrid.ExpandNode(treeNode); } parentNode = treeNode; var parentkey = parentNode.Item as EmployeeInfo; newItem = new EmployeeInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, Salary = record.Salary, Title = record.Title, ReportsTo = parentkey.ID }; } IList sourceCollection = null; if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { if (treeNode.ParentNode != null) { var collection = AssociatedObject.sfTreeGrid.View.GetPropertyAccessProvider().GetValue(treeNode.ParentNode.Item, AssociatedObject.sfTreeGrid.ChildPropertyName) as IEnumerable; sourceCollection = GetSourceListCollection(collection); } else { sourceCollection = GetSourceListCollection(AssociatedObject.sfTreeGrid.View.SourceCollection); } itemIndex = sourceCollection.IndexOf(data); if (dropPosition == "DropBelow") { itemIndex += 1; } } else if (dropPosition == "DropAsChild") { var collection = AssociatedObject.sfTreeGrid.View.GetPropertyAccessProvider().GetValue(data, AssociatedObject.sfTreeGrid.ChildPropertyName) as IEnumerable; sourceCollection = GetSourceListCollection(collection); if (sourceCollection == null) { var list = data.GetType().GetProperty(AssociatedObject.sfTreeGrid.ChildPropertyName).PropertyType.CreateNew() as IList; if (list != null) { AssociatedObject.sfTreeGrid.View.GetPropertyAccessProvider().SetValue(treeNode.Item, AssociatedObject.sfTreeGrid.ChildPropertyName, list); sourceCollection = list; } } itemIndex = sourceCollection.Count; } sourceCollection.Insert(itemIndex, newItem); AssociatedObject.sfTreeGrid.SelectionController.ResumeUpdates(); (AssociatedObject.sfTreeGrid.SelectionController as TreeGridRowSelectionController).RefreshSelection(); e.Handled = true; } } (AssociatedObject.listView.ItemsSource as ObservableCollection <EmployeeInfo>).Remove(record as EmployeeInfo); } }