Hi
My SfTreeGrid is binded to an ObservableCollection<MyObject>
MyObject contains an ObservableCollection<MyObject> Leafs and so on.
When i add new objects to Leafs programmatically, the TreeGrid updates correctly by notification from ViewModel.
When i perform a Drag and Drop, the node dropped is "moved" automatically to its new parent and ObservableCollection Leafs is not updated.
I assume that this is a usual sfTreeGrid behavior.
But if i programmatically update the ObservableCollection Leafs, after Drag and Drop operation, the binding notification create a duplicate node in the parent Node. I think because the new parent Node doesn't notify the new child node to the ObservableCollection.
So, how is it possibile to avoid or manage this behavior?
For example, i don't need the automatic addition of the node by sfTreeGrid.
This is my code
private MyObject TempDrag{get;set;}
private void NodeDragStart(object sender, TreeGridRowDragStartEventArgs e)
{
TempDrag= e.DraggingNodes[0].Item as MyObject;
}
private void NodeDragOver(object sender, TreeGridRowDragOverEventArgs e)
{
var dropPosition = e.DropPosition.ToString();
if (dropPosition == "None") return;
if (dropPosition == "DropAbove") return;
if (dropPosition == "DropBelow") return;
var targetLeaf = e.TargetNode.Item as MyObject;
}
private void NodeDrop(object sender, TreeGridRowDropEventArgs e)
{
var dropPosition = e.DropPosition.ToString();
if (dropPosition == "None") return;
if (dropPosition == "DropAbove") return;
if (dropPosition == "DropBelow") return;
if (e.IsFromOutSideSource) return;
var targetLeaf = e.TargetNode.Item as MyObject;
if (targetLeaf.Type.ToString() != "Document" && targetLeaf.Type.ToString() != "Array")
{
e.Handled = true;
return;
}
var memNode = e.DraggingNodes[0].Item as MyObject;
var parentMemNode = memNode.Parent;
targetLeaf.AddLeaf(memNode); //Here i add MyObject to the new Parent but it cause a duplicate node in the sfTreeView
parentMemNode.DelLeaf(memNode); //Here i remove MyObject from the old Parent
}