Telerik Forums
UI for WinForms Forum
1 answer
24 views

We have been using the TreeView in our software for some time now. However, recently, we noticed that it's not behaving as we have coded it. We had code that changed the Forcolor and Font when a node was selected. However, this doesn't seem to be working anymore. Attached is a sample code. Any help would be greatly appreciated.

 

FYI, we are using Telerik for Winforms: 2024.3.924.462

TIA



using System;
using System.Collections.Generic;
using System.Drawing;
using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace TestNodeColorChange
{
   public partial class RadForm1 : Telerik.WinControls.UI.RadForm
   {
      #region Private Fields

      private string selectedNodeKey = string.Empty;

      #endregion Private Fields

      #region Public Constructors

      public RadForm1()
      {
         InitializeComponent();
         Load += FormLoading;
      }

      #endregion Public Constructors

      #region Private Methods

      private void FormLoading(object sender, EventArgs e)
      {
         List<TreeViewData> list = new List<TreeViewData>()
         {
            new TreeViewData { key = 1, DisplayValue = "Level 1" },
            new TreeViewData { key = 2, parentKey = 1, DisplayValue = "Branch A" },
            new TreeViewData { key = 3, parentKey = 1, DisplayValue = "Branch B" },
            new TreeViewData { key = 4, parentKey = 1, DisplayValue = "Branch C" }
         };

         radTreeView1.ChildMember = "key";
         radTreeView1.DisplayMember = "DisplayValue";
         radTreeView1.ParentMember = "parentKey";
         radTreeView1.DataSource = list;

         radTreeView1.ExpandAll();

         radTreeView1.SelectedNodeChanged += SelectedNodeChanged;
         radTreeView1.NodeFormatting += NodeFormatting;
      }

      private void NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
      {
         if (e.NodeElement is LightVisualElement lve)
         {
            lve.ResetValue(VisualElement.ForeColorProperty, ValueResetFlags.Local);
            lve.ResetValue(VisualElement.FontProperty, ValueResetFlags.Local);

            if (e.Node.Value.ToString() == selectedNodeKey)
            {
               lve.Font = new Font(lve.Font.FontFamily, lve.Font.Size, FontStyle.Bold);
               lve.ForeColor = Color.Purple;
               radTreeView1.NodeFormatting -= NodeFormatting;
               radTreeView1.Refresh();
               radTreeView1.NodeFormatting += NodeFormatting;
               Console.WriteLine("NodeFormatting: " + selectedNodeKey);
               Console.WriteLine("NodeFormatting: " + e.NodeElement.ForeColor.ToString());
               Console.WriteLine("NodeFormatting: " + ((e.NodeElement.Font.Style & FontStyle.Bold) != 0));
            }
         }
      }

      private void SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
      {
         selectedNodeKey = e.Node.Value.ToString();
         Console.WriteLine("SelectedNodeChanged: " + selectedNodeKey);
         radTreeView1.Nodes.Refresh();
      }

      #endregion Private Methods

      #region Internal Classes

      internal class TreeViewData
      {
         #region Public Properties

         public string DisplayValue { get; set; }
         public int key { get; set; }
         public int? parentKey { get; set; }

         #endregion Public Properties
      }

      #endregion Internal Classes
   }
}

Nadya | Tech Support Engineer
Telerik team
 answered on 03 Apr 2025
1 answer
30 views

Hello,

is there any alternate available to apply specific theme directly on win form controls other than making a change in stylesheet (to apply different colors and appearance?) basically, for specific theme user wants to apply different color. one option is to create .tsp file and add it to resource. so is there any other way possible where user don't need to create. tsp or any other file and by using direct property he can achieve the same.  (controls like date time picker, calendar, tree view, Rad buttons etc.)

Thank you.

Dinko | Tech Support Engineer
Telerik team
 answered on 13 Mar 2025
1 answer
33 views

Hi,

Is it possible to override the colour and width of the horizontal drag / drop visual cue? If so can you give me an example ?

 

Cheers

Toby

Dinko | Tech Support Engineer
Telerik team
 answered on 04 Nov 2024
1 answer
86 views
Hello, can you please tell me how to properly localize radtreeview nodes text? The localization is working properly for other controls like rad menu items: In case of them, I only had to change the language property in parent RadForm, and set text property in particular language for that control and it worked fine. However, it cannot be done for tree nodes. For tree nodes I tried changing the language property in the parent form then opening the property builder where I set Text property. It turns out that the text set in this property is the text that is shown in all languages, not just in the one selected in the main form. So, how to do this?
Nadya | Tech Support Engineer
Telerik team
 answered on 16 Sep 2024
1 answer
86 views

Hello Team

How to set horizontal scroll position left most in the RadTreeView ?

Note: telerik version 2024.1.312.48

Attached screenshot for reference:

Thanks

Rajkannan

Dinko | Tech Support Engineer
Telerik team
 answered on 10 Jun 2024
1 answer
73 views

Hello,

We have a RadTreeView control inside a ToolWindow (with Dock = Fill) in a RadDock control. The nodes are added to the tree programmatically and AllowArbitraryItemHeight=false and TreeViewElement.AutoSizeItems=true. There is no ItemHeight set at all. We are sporadically getting an issue where the RadTreeView won’t let the user scroll to the bottom of the tree. We can’t consistently reproduce this error however. Is there any advice you can give how to try figure out what is going on?

Thanks,

Hayley

Nadya | Tech Support Engineer
Telerik team
 answered on 15 May 2024
1 answer
124 views
Hello,

I have a RadTreeView control and a RadDock control together in a WinForms app. The user needs to be able to drag a node from the RadTreeView to either the DocumentTabStrip part of RadDock or the control thats in a DocumentWindow. How do I tell which part of the RadDock the node is being dropped on? Im currently using the  TreeViewElement.DragDropService to handle the PreviewDragDrop method but the RadDropEventArgs.HitTarget gives me a RadPageViewStripElement regardless of where i drop the node. If I am dropping in the content area of the a document window (floating or docked) how do i get the actual DocumentWindow object itself?

Let me know if more information is required.

Thanks,

Hayley
Dinko | Tech Support Engineer
Telerik team
 answered on 21 Mar 2024
2 answers
83 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
153 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
326 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
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
DropDownList
Buttons, RadioButton, CheckBox, etc
ListView
ComboBox and ListBox (obsolete as of Q2 2010)
Chart (obsolete as of Q1 2013)
Form
PageView
MultiColumn ComboBox
TextBox
RichTextEditor
PropertyGrid
Menu
RichTextBox (obsolete as of Q3 2014 SP1)
Panelbar (obsolete as of Q2 2010)
PivotGrid and PivotFieldList
Tabstrip (obsolete as of Q2 2010)
MaskedEditBox
CommandBar
PdfViewer and PdfViewerNavigator
ListControl
Carousel
Diagram, DiagramRibbonBar, DiagramToolBox
GanttView
Panorama
New Product Suggestions
Toolstrip (obsolete as of Q3 2010)
VirtualGrid
AutoCompleteBox
Label
Spreadsheet
ContextMenu
Panel
Visual Studio Extensions
TitleBar
Documentation
SplitContainer
Map
DesktopAlert
ProgressBar
CheckedDropDownList
TrackBar
MessageBox
Rotator
SpinEditor
StatusStrip
CheckedListBox
LayoutControl
SyntaxEditor
Wizard
ShapedForm
TextBoxControl
DateTimePicker
CollapsiblePanel
Conversational UI, Chat
TabbedForm
CAB Enabling Kit
GroupBox
DataEntry
ScrollablePanel
ScrollBar
WaitingBar
ImageEditor
Tools - VSB, Control Spy, Shape Editor
BrowseEditor
DataFilter
ColorDialog
FileDialogs
Gauges (RadialGauge, LinearGauge, BulletGraph)
ApplicationMenu
RangeSelector
CardView
WebCam
BindingNavigator
PopupEditor
RibbonForm
Styling
TaskBoard
Barcode
Callout
ColorBox
PictureBox
FilterView
Accessibility
VirtualKeyboard
NavigationView
DataLayout
ToastNotificationManager
ValidationProvider
CalculatorDropDown
Localization
TimePicker
ButtonTextBox
FontDropDownList
Licensing
BarcodeView
BreadCrumb
Security
LocalizationProvider
Dictionary
Overlay
Flyout
Separator
SparkLine
TreeMap
StepProgressBar
SplashScreen
ToolbarForm
NotifyIcon
DateOnlyPicker
Rating
TimeSpanPicker
Calculator
OfficeNavigationBar
TaskbarButton
HeatMap
SlideView
PipsPager
AIPrompt
TaskDialog
TimeOnlyPicker
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?