Node Expander Image is blank

1 Answer 88 Views
Designs, skins, themes Forum suggestions Let's talk about telerik (the good and the bad) Miscellaneous
Nishant
Top achievements
Rank 1
Nishant asked on 13 Sep 2022, 01:49 PM

I am using a "RadTreeView" control where I have declared an event which handles the formatting of the node and also have NodeExpandedChanged event.

The main purpose of the NodeFormatting event is to control the Expander image

private void tvwDocuments_NodeFormatting(object eventSender, TreeNodeFormattingEventArgs eventArgs) { RadTreeNode Node = eventArgs.Node; //Check if Node is the root node, else check if it has no children, and set expand/collapse state accordingly if (Node.Parent == null) { eventArgs.NodeElement.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed; //Collapsed hides the element completely, hidden just makes it not visible but maintains spacing for it } else if (Node.Nodes.Count == 0) { //Disable drawing of the sign image, then set its size to 0 so that the lines are drawn underneath. eventArgs.NodeElement.ExpanderElement.SignImage = null; eventArgs.NodeElement.ExpanderElement.SignSize = new Size(0, 0); }

 

In my application I have a tree that looks something like the attached image (Tree Structure.png). From the image it will be evident that all nodes are expanded.

The issue what I am facing is, when all nodes are expanded and when the very first node of the parent is collapsed; all the respective nodes "ExpanderImage" is blank. (please refer attached screenshot (UpdatedTreeStructure.png))

Dess | Tech Support Engineer, Principal
Telerik team
commented on 13 Sep 2022, 01:51 PM

Hello, Nishant,

Since the product in this forum thread is not specified, it would be greatly appreciated if you can share what is the exact Telerik product that you are currently using. Thus, the product will be properly updated and the respective community will gladly assist you.

Nishant
Top achievements
Rank 1
commented on 13 Sep 2022, 02:03 PM

Telerik for Winform

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Sep 2022, 08:26 AM

Hi, Nishant,

If I understand your requirement correctly, you need to hide the expander item for nodes without any children. Please correct me if I am wrong.

For this purpose, it is necessary to handle the NodeFormatting event. However, please have in mind that node elements are created only for the currently visible nodes and they are being reused during operations like scrolling, expanding, collapsing. In order to avoid any undesired style applied to unexpected visual nodes, make sure that the applied style settings are properly reset. In other words, each statement should have its else clause for restting:

        public RadForm1()
        {
            InitializeComponent();

            this.radTreeView1.ShowRootLines = true;
            this.radTreeView1.ShowLines = true;
            this.radTreeView1.LineStyle = TreeLineStyle.Dot;
            this.radTreeView1.LineColor = Color.Black;
        }

        private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
        { 
             
            if (e.Node.Parent == null || e.Node.Nodes.Count == 0)
            {
                e.NodeElement.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;  
            }
            else if (e.Node.Nodes.Count == 0)
            { 
                e.NodeElement.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Visible; 
            }
            else
            {
                e.NodeElement.ExpanderElement.ResetValue(LightVisualElement.VisibilityProperty, ValueResetFlags.Local);
 
            }
        }

I have attached my sample project for your reference. Please give it a try and see how it works on your end.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Designs, skins, themes Forum suggestions Let's talk about telerik (the good and the bad) Miscellaneous
Asked by
Nishant
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or