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 ...
Current limits
I can't get all those infos at the DragEnding nor in the DragEnded event. At the moment:
What I do now is not well done:
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;
}
}
}
In my application, I'm able to bind a TreeView to a Well object in my application through object-relational binding as such:
this.wellTreeView = new RadTreeView();
BindingList<Well> wells = new BindingList<Well>() { well };
this.wellTreeView.DataSource = wells;
this.wellTreeView.DisplayMember = "name\\name\\name";
this.wellTreeView.ChildMember = "wells\\layers\\items";
This works and I am able to view the TreeView hierarchy and select the nodes in the form. However, when trying to get the nodes in code, the wellTreeView is empty (0 nodes) and throws an Index out of range error in:
RadTreeNode node = wellTreeView.Nodes[0];
My Well class is defined like so:
public class Well
{
public string name {get; set;}
public List<Layer> layers {get; set;}
}
public class Layer
{
public string name {get; set;};
public List<Item> items {get; set;}
}
public class Item
{
public string name {get; set;};
public decimal length {get; set;}
}
I don't understand why the wellTreeView is empty without any nodes despite being able to view the tree in the form. Surely the well is bound to the TreeView?
Hi,
How to change fore color for specific node ? i have 3 level node and want to change fore color for 3rd level node only, below the code i used but not color not changed.
Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Dim filePath As String = "20230824.124217\20230824.1242174616\00001.tif" Dim filenode As String() = filePath.Split("\") Dim addNode As String = "" For i = 0 To filenode.Count - 1 If addNode = "" Then addNode = filenode(i) Else addNode = addNode & "\" & filenode(i) End If Dim searchKey As String = addNode Dim nodeExists As Boolean = CheckNodeExists(RadTreeView1.Nodes, searchKey) If Not nodeExists Then RadTreeView1.ForeColor = Color.Red Dim folderNode As RadTreeNode = New RadTreeNode() folderNode.ForeColor = System.Drawing.Color.Green RadTreeView1.AddNodeByPath(addNode) End If Next RadTreeView1.Update() RadTreeView1.Refresh()
End Sub
Private Function CheckNodeExists(nodes As RadTreeNodeCollection, searchKey As String) As Boolean
For Each node As RadTreeNode In nodes
If node.FullPath = searchKey Then
' Node found
Return True
End If
' Recursively check child nodes
If node.Nodes.Count > 0 Then
If CheckNodeExists(node.Nodes, searchKey) Then
Return True
End If
End If
Next
' Node not found
Return False
End Function
Pls reply asap.
Thanks and Regards
Aravind
how to refresh the radtreeview ui while the datasource of the radtreeview changed .for example add or update one record
Hello All,
I'm working on an active directory project where the RadTreeView requires it's nodes to have images according to the nodes respective containers (I.E. User Accounts will have an user icon). I have posted some code relating to my issue. I hope someone here can shed some light on this and tell me what it is I'm doing wrong.
To be clear on this, the nodes show active directory binded data but not the images. Thank you in advance.
public void subEnumerateChildren(RadTreeNode oRootNode)
{
DirectoryEntry deParent = new DirectoryEntry("LDAP://RootDSE");
foreach (DirectoryEntry deChild in deParent.Children)
{
RadTreeNode oChildNode = oRootNode.Nodes.Add(deChild.Path);
switch (deChild.SchemaClassName)
{
case "computer":
oChildNode.ImageIndex = 6;
break;
case "user":
oChildNode.ImageIndex = 7;
break;
case "group":
oChildNode.ImageIndex = 8;
break;
case "organizationalUnit":
oChildNode.ImageIndex = 3;
break;
case "container":
oChildNode.ImageIndex = 1;
break;
case "publicFolder":
oChildNode.ImageIndex = 5;
break;
default:
oChildNode.ImageIndex = 1;
break;
}
oChildNode.Tag = deChild;
oChildNode.Text = deChild.Name.Substring(3).Replace("\\", "");
}
}
Hi, i have radtreeview, in that dynamically i loaded node upto 4 levels, from that i want to select and expand specific node only,
Here i attach sample treeview structure, from that i want to select and expand "11\20\8" and others should be collapsed by button click.
Please reply asap.
Regards
Aravind
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load RadTreeView1.AllowDragDrop = True RadTreeView1.AllowDrop = True ' Add event handlers for drag and drop events AddHandler RadTreeView1.DragEnter, AddressOf RadTreeView1_DragEnter AddHandler RadTreeView1.DragDrop, AddressOf RadTreeView1_DragDrop End Sub Private Sub RadTreeView1_DragEnter(sender As Object, e As DragEventArgs) Handles RadTreeView1.DragEnter ' Check if the data being dragged is a RadTreeNode If e.Data.GetDataPresent(GetType(RadTreeNode)) Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Private Sub RadTreeView1_DragDrop(sender As Object, e As DragEventArgs) Handles RadTreeView1.DragDrop ' Check if the data being dragged is a RadTreeNode If e.Data.GetDataPresent(GetType(RadTreeNode)) Then ' Get the dragged node Dim draggedNode As RadTreeNode = CType(e.Data.GetData(GetType(RadTreeNode)), RadTreeNode) ' Get the target node Dim targetNode As RadTreeNode = RadTreeView1.GetNodeAt(RadTreeView1.PointToClient(New Point(e.X, e.Y))) ' Get the full path of the dragged node Dim draggedNodePath As String = draggedNode.FullPath ' Get the full path of the target node Dim targetNodePath As String = targetNode.FullPath ' Do something with the full paths MessageBox.Show("Dragged Node Path: " & draggedNodePath & vbCrLf & "Target Node Path: " & targetNodePath) End If End Sub
Please advice me what i make mistake ? i try to get source and destination node after drag and drop nodes
Please asap.
Regards
Aravind
Hi,
1. How to get radtreeview drag and drop event to handle to get source and destination full path node using vb.net. I tried but i can get both source and destination as same node. I provide treeview node sample structure.
Family
----Father
---Son1
---Son2
----Mother
---Son3
---Son4
Hi Everyone,
I use a RadTreeView control on my form. I have a client table and a project table. Both tables have a DeletionStatus boolean field/property.
This is how I set the control up:
this.tvProjectClient.DataSource = clientBindingSource;
this.tvProjectClient.DisplayMember = "FullName";
this.tvProjectClient.ValueMember = "ClientId";
this.tvProjectClient.RadContextMenu = this.rcmProject;
this.tvProjectClient.RelationBindings.Clear();
this.tvProjectClient.RelationBindings.Add(new RelationBinding(this.projectBindingSource, "Name", "ClientId", "ClientId", "ProjectId"));
Now i want to create a FilterDescriptor to filter DeletionStatus to false on the Client table to be like:
FilterDescriptor filterDescriptor = new FilterDescriptor(); filterDescriptor.Value = "False"; filterDescriptor.Operator = FilterOperator.IsEqualTo; filterDescriptor.PropertyName = "DeletionStatus";
My question is, how to I change the property name to reference the client (or project) table for DeletionStatus? I have tried Client.DeletionStatus and ClientRow.DeletionStatus but the control does not register it.
Any ideas? I do not want to change field names if possible.
Many thanks, JB