Telerik Forums
UI for WinForms Forum
2 answers
27 views

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;
        }
    }
}

Nadya | Tech Support Engineer
Telerik team
 answered on 17 Oct 2023
1 answer
60 views

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?



Dinko | Tech Support Engineer
Telerik team
 answered on 11 Oct 2023
1 answer
111 views

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

 
Dess | Tech Support Engineer, Principal
Telerik team
 answered on 28 Aug 2023
1 answer
27 views

how to refresh the radtreeview ui while the datasource of the radtreeview changed .for example add or update one record

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 15 Aug 2023
1 answer
35 views

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("\\", "");

            }
        }

Dinko | Tech Support Engineer
Telerik team
 answered on 26 Jul 2023
1 answer
84 views

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

Dinko | Tech Support Engineer
Telerik team
 answered on 01 Jun 2023
1 answer
72 views
Hi,
   I try to get even for dragdrop once node move to another location, i used following code to get event, but not success, here i attach code. i make true for   RadTreeView1.AllowDragDrop = True and  RadTreeView1.AllowDrop = True


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

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 23 May 2023
1 answer
73 views

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

 Here i drag and drop Son4 under the Son1, so i need to get source as Family/Mother/Son4 and destination as  Family/Father/Son1/Son4.

2. How to restrict to drop nodes in level 1(Family) and  level 3 (Son1,Son2,Son3,Son4), i need to move nodes Son1,Son2,Son3,Son4 under Father and Mother node, not to create child node under Son1,Son2,Son3,Son4, I mean move Son2 above Son1, same like Son4 move above Son3 and also move Son3 or 4 move to below Father node, same like Son1 or 2 move below Mother as child node.


Please reply asap.

Regards
Aravind
Aravind
Top achievements
Rank 2
Iron
Iron
Iron
 updated question on 22 May 2023
3 answers
59 views

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

James
Top achievements
Rank 1
Iron
 answered on 21 Apr 2023
1 answer
61 views

Is there a Desktop equivalent example of this example?

https://demos.telerik.com/aspnet-ajax/listbox/examples/applicationscenarios/treeviewdraganddrop/defaultcs.aspx

I'm struggling to figure out the way to handle this. I have a treeview showing a list of accounts, and a treeview that allows for grouping these accounts in a hierarchy. Both have underlying classes that are populated from a database.

I'd like to allow my front-end users to drag and drop accounts from the listView to the treeView. The one attribute they have in common is an AccountNumber. All other attributes in the Hierarchy can be derived from other controls on the form. 

I read about adding a DataConverter, but cannot figure out how to implement this. For example, on this page: https://docs.telerik.com/devtools/wpf/controls/dragdropmanager/behaviors/listboxdragdropbehavior
it has a reference to DataConverter (but the definition for that seems to lack). 

The other references I've seen is to a DragDropManager, but I don't seem to be able to find concrete examples for Desktop for that, either.

Googling so far hasn't really helped.

Any assistance would be greatly appreciated!

Martin Ivanov
Telerik team
 answered on 19 Apr 2023
Narrow your results
Selected tags
Tags
GridView
General Discussions
Scheduler and Reminder
Dock
RibbonBar
Themes and Visual Style Builder
ChartView
Calendar, DateTimePicker, TimePicker and Clock
Buttons, RadioButton, CheckBox, etc
DropDownList
ComboBox and ListBox (obsolete as of Q2 2010)
ListView
Chart (obsolete as of Q1 2013)
Form
PageView
MultiColumn ComboBox
TextBox
Menu
RichTextEditor
PropertyGrid
RichTextBox (obsolete as of Q3 2014 SP1)
Panelbar (obsolete as of Q2 2010)
Tabstrip (obsolete as of Q2 2010)
PivotGrid and PivotFieldList
MaskedEditBox
CommandBar
PdfViewer and PdfViewerNavigator
ListControl
Carousel
Diagram, DiagramRibbonBar, DiagramToolBox
Panorama
GanttView
New Product Suggestions
Toolstrip (obsolete as of Q3 2010)
AutoCompleteBox
Label
VirtualGrid
Spreadsheet
ContextMenu
Panel
Visual Studio Extensions
TitleBar
Documentation
SplitContainer
Map
DesktopAlert
ProgressBar
Rotator
TrackBar
MessageBox
CheckedDropDownList
SpinEditor
StatusStrip
CheckedListBox
Wizard
ShapedForm
SyntaxEditor
TextBoxControl
LayoutControl
CollapsiblePanel
Conversational UI, Chat
DateTimePicker
CAB Enabling Kit
TabbedForm
DataEntry
GroupBox
ScrollablePanel
WaitingBar
ImageEditor
ScrollBar
Tools - VSB, Control Spy, Shape Editor
BrowseEditor
DataFilter
ColorDialog
FileDialogs
Gauges (RadialGauge, LinearGauge, BulletGraph)
ApplicationMenu
RangeSelector
CardView
WebCam
BindingNavigator
PopupEditor
RibbonForm
TaskBoard
Barcode
Styling
ColorBox
PictureBox
Callout
VirtualKeyboard
FilterView
Accessibility
DataLayout
NavigationView
ToastNotificationManager
CalculatorDropDown
Localization
TimePicker
ValidationProvider
FontDropDownList
Licensing
BreadCrumb
ButtonTextBox
LocalizationProvider
Dictionary
Overlay
Security
Separator
SparkLine
TreeMap
StepProgressBar
SplashScreen
ToolbarForm
NotifyIcon
Rating
TimeSpanPicker
BarcodeView
Calculator
OfficeNavigationBar
Flyout
TaskbarButton
HeatMap
SlideView
PipsPager
+? more
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?