Hello!
I'm struggeling tracking move actions via the DragStarting, DragEnding & DragEnded event of the RadTreeView control.
The informatin provided by the event args are nearly impossible to use, as they are inconsitent as it looks like. Probably I just miss something, but that's why I'm writing this here. :)
What I need:
I need to check if the previous Node in the previous parent can be dropped to the new parent at the new position. This is a more complex check I can't explain in detail, but to clarify: I need ...
- the old parent
- the old index of the node within the old parent
- the new parent
- the new index of the node in the new parent
Current limits
I can't get all those infos at the DragEnding nor in the DragEnded event. At the moment:
- Only the DragEnded event have 100% accurate infos about the new parent and new new index of the node in the new parent.
- Only the DragEnding event has 100% accurate infos about the old parent and the old index of the node.
What I do now is not well done:
- On DragEnding don't use the "Controller.Allow..." methods to see if the actions "Controller.Move..." and "Controller.SetNewEntilityParent" will succes. Instead I just catch the exception.
- The exact destination I can't really track. So, I do some hacky checks to suppose the new parent and the new index of the node in the new parent. This is still not accurate and still lead to IndexOutOfBoundExceptions that the try-catch also catches.
My question
Is there any way to either track down the accurate new parent and the new index of the node in the new parent on the DragEnding event? I need to know them to cancel the drag event if the action is not allow and very specific cases.
Thank you in advance for an answer! We hope to get a solution soon. I already spend a lot of hours (several days) to this issue without a good solution.
This might also be a support ticket, but maybe someone of the community have a similar issue or already have a workaround/solution for it.
Code sample of a current implementation:
private void RadTreeView_BgrTree_DragStarting(object sender, RadTreeViewDragCancelEventArgs e)
{
if (e.Node is not null)
{
oldNodeIndex = e.Node.Index;
oldNodeParent = CheckForRootNode(e.Node.Parent);
}
}
private void RadTreeView_BgrTree_DragEnding(object sender, RadTreeViewDragCancelEventArgs e)
{
IMatrixTarget draggingTarget = e.Node?.Tag as IMatrixTarget;
Entility newParentEntility = null;
int indexToInsert = 0;
void insertInSameParent(int offset)
{
if (e.TargetNode.Parent is not null)
newParentEntility = CheckForRootNode(e.TargetNode.Parent)?.Tag as Entility;
indexToInsert = e.TargetNode.Index + offset;
};
void insertAsChild(int offset)
{
if (e.TargetNode is not null)
newParentEntility = CheckForRootNode(e.TargetNode)?.Tag as Entility;
indexToInsert = newParentEntility.Childs.Count;
};
switch (e.DropPosition)
{
case DropPosition.BeforeNode:
insertInSameParent(0);
break;
case DropPosition.AfterNode:
{
if (ReferenceEquals(e.TargetNode.Parent, e.Node.Parent))
{
if (draggingTarget is Entility draggingEntility && draggingEntility.Index > e.TargetNode.Index)
insertInSameParent(0);
else
insertInSameParent(-1);
}
else if (draggingTarget is Entility && ReferenceEquals(((Entility)draggingTarget).Parent, e.TargetNode.Tag))
insertAsChild(-1);
else
insertAsChild(0);
break;
}
case DropPosition.AsChildNode:
insertAsChild(0);
break;
}
if (newParentEntility is not null)
{
try
{
if (draggingTarget is Einfluss)
Controller.MoveIMatrixTarget(draggingTarget, indexToInsert);
else if (draggingTarget is Entility entility)
Controller.SetNewEntilityParent(newParentEntility, new[] { entility }, indexToInsert, false, false);
}
catch (Exception)
{
e.Cancel = true;
}
}
}