Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Avoid collapsing on double click

Answered Avoid collapsing on double click

Feed from this thread
  • Michael avatar

    Posted on Aug 27, 2008 (permalink)

    Nachricht Hello,

    Is there a way to avoid collapsing of a RadTreeNode when double clicking on it? When possible before the ExpandAnimation starts.

    Regards,
    Michael

    Reply

  • Jordan Jordan admin's avatar

    Posted on Aug 27, 2008 (permalink)

    Hello Michael,

    With the current implementation the NodeExpandedChanging event is fired after the collapse animation has finished.
    However, the following code turns that animation just before the node is collapsed and then turns it back on:
    void radTreeView1_NodeMouseUp(object sender, RadTreeViewMouseEventArgs e) 
            { 
                this.radTreeView1.ExpandAnimation = ExpandAnimation.Opacity; 
            } 
     
            void radTreeView1_NodeMouseDown(object sender, RadTreeViewMouseEventArgs e) 
            { 
                if (e.OriginalEventArgs.Clicks > 1 && e.Node.Expanded) 
                { 
                    this.radTreeView1.ExpandAnimation = ExpandAnimation.None; 
                } 
            } 
     
            void radTreeView1_NodeExpandedChanging(object sender, RadTreeViewCancelEventArgs e) 
            { 
                if (!e.Node.Expanded) 
                { 
                    return
                } 
     
                RadTreeNode node = e.Node; 
                TreeNodeUI uiNode = null
                foreach (TreeNodeUI treeNodeUI in this.radTreeView1.TreeViewElement.Items) 
                { 
                    if (treeNodeUI.AssociatedTreeNode == node) 
                    { 
                        uiNode = treeNodeUI; 
                        break
                    } 
                } 
     
                if (uiNode != null
                { 
                    if (uiNode.BoundingRectangle.Contains(this.radTreeView1.PointToClient(Cursor.Position))) 
                    { 
                        e.Cancel = true
                    } 
                } 
            } 

    Don't hesitate to contact us if you have other questions.

    Regards,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.


    Reply

  • Michael avatar

    Posted on Aug 27, 2008 (permalink)

    <div style="border: 1px solid rgb(127, 157, 185); overflow: auto; background-color: white; line-height: 100% ! important; font-family: Courier New; font-size: 11px;"><table style="border-width: 0px; border-bottom: 0px solid rgb(238, 238, 238); margin: 2px 0px; width: 99%; border-collapse: collapse; background-color: rgb(255, 255, 255);" cellpadding="0" cellspacing="0"><col style="border-bottom: 1px solid rgb(247, 247, 247); font-family: Courier New; font-size: 11px; padding-left: 10px; white-space: nowrap;"><tbody><tr><td><font style="font-size: 11px;">... </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);"><font style="color: blue;">if</font><font style="font-size: 11px;">(uiNode != </font><font style="color: blue;">null</font><font style="font-size: 11px;">) { </font></td></tr><tr><td>    <font style="color: blue;">int</font><font style="font-size: 11px;"> offset = 30; </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);">    Point location = uiNode.BoundingRectangle.Location; </td></tr><tr><td>    Size size = uiNode.BoundingRectangle.Size; </td></tr><tr><td style="background-color: rgb(247, 247, 247);">    Rectangle bounding = <font style="color: blue;">new</font><font style="font-size: 11px;"> Rectangle(location.X + offset, location.Y, size.Width - offset, size.Height); </font></td></tr><tr><td>    <font style="color: blue;">if</font><font style="font-size: 11px;">(bounding.Contains(</font><font style="color: blue;">this</font><font style="font-size: 11px;">.radTreeView1.PointToClient(Cursor.Position))) { </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);">        e.Cancel = <font style="color: blue;">true</font><font style="font-size: 11px;">; </font></td></tr><tr><td>    } </td></tr><tr><td style="background-color: rgb(247, 247, 247);">} </td></tr></tbody></table></div><div style="border: 1px solid rgb(127, 157, 185); overflow: auto; background-color: white; line-height: 100% ! important; font-family: Courier New; font-size: 11px;"><table style="border-width: 0px; border-bottom: 0px solid rgb(238, 238, 238); margin: 2px 0px; width: 99%; border-collapse: collapse; background-color: rgb(255, 255, 255);" cellpadding="0" cellspacing="0"><col style="border-bottom: 1px solid rgb(247, 247, 247); font-family: Courier New; font-size: 11px; padding-left: 10px; white-space: nowrap;"><tbody><tr><td><font style="font-size: 11px;">... </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);"><font style="color: blue;">if</font><font style="font-size: 11px;">(uiNode != </font><font style="color: blue;">null</font><font style="font-size: 11px;">) { </font></td></tr><tr><td>    <font style="color: blue;">int</font><font style="font-size: 11px;"> offset = 30; </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);">    Point location = uiNode.BoundingRectangle.Location; </td></tr><tr><td>    Size size = uiNode.BoundingRectangle.Size; </td></tr><tr><td style="background-color: rgb(247, 247, 247);">    Rectangle bounding = <font style="color: blue;">new</font><font style="font-size: 11px;"> Rectangle(location.X + offset, location.Y, size.Width - offset, size.Height); </font></td></tr><tr><td>    <font style="color: blue;">if</font><font style="font-size: 11px;">(bounding.Contains(</font><font style="color: blue;">this</font><font style="font-size: 11px;">.radTreeView1.PointToClient(Cursor.Position))) { </font></td></tr><tr><td style="background-color: rgb(247, 247, 247);">        e.Cancel = <font style="color: blue;">true</font><font style="font-size: 11px;">; </font></td></tr><tr><td>    } </td></tr><tr><td style="background-color: rgb(247, 247, 247);">} </td></tr></tbody></table></div>Nachricht
    Thanks a lot !
    I would never have found this...
     
    But I still have a little problem:
    I forgot to say, that I still want to be able to collapse the node with a single click on the little sign preceding each node text.
    So I retract the bounding rectangle which is used to cancel the NodeExpandedChanging event:
     
    ... 
    if(uiNode != null) { 
        int offset = 30; 
        Point location = uiNode.BoundingRectangle.Location; 
        Size size = uiNode.BoundingRectangle.Size; 
        Rectangle bounding = new Rectangle(location.X + offset, location.Y, size.Width - offset, size.Height); 
        if(bounding.Contains(this.radTreeView1.PointToClient(Cursor.Position))) { 
            e.Cancel = true
        } 
     
    I estimate an offset of 30, just by testing.
     
    Is it possible to get the position where the node begins (the position of the image)?
    And I am not sure from where the position is taken, is it from the left border of the entire tree view, or from the left border of the actual node level?
    Or is there another trick?
     
    Regards,
    Michael Pradier

    Reply

  • Jordan Jordan admin's avatar

    Posted on Aug 28, 2008 (permalink)

    Hi Michael,

    The X coordinate of the position of a TreeNodeUI object is:

    uiNode.BoundingRectangle.Left

    The bounds of the TreeNodeUI objects are in client coordinates, i.e. relative to the tree view control.

    However, you should not need to offset the bounding rectangle, because it does not contain the area of the expand/collapse button (because it is represented by a different object). I tested again the code in my response and I could collapse the node by clicking on the expand/collapse button.

    So, please try without offsetting the bounding rectangle. If it does not work I will need some more information about your case - for example what your structure of nodes looks like.

     
    Sincerely yours,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Michael avatar

    Posted on Aug 28, 2008 (permalink)

    Nachricht
    Hello,
     
    I test your code in an new empty project and it works fine. But in my current project I am not able to collapse a node by clicking on the button.
    It is only possible if I move the mouse cursor away from the current line during the animation is running.
     
    It must be something wrong in my code... so I have continue searching.
    I will recontact you if I found something or if I have some other questions.
    Thanks,
     
    Michael Pradier

    Reply

  • Answer Michael avatar

    Posted on Aug 28, 2008 (permalink)

    Hello again,

    I have got it !
    The problem was that I was using full row selection in my tree view. So the bounding rectangle was the full line.
    I solve this by deactivating temporarily the FullRowSelect:

    if(uiNode != null) { 
     this.radTreeView1.FullRowSelect = false
     if(uiNode.BoundingRectangle.Contains(this.radTreeView1.PointToClient(Cursor.Position))) e.Cancel = true
     this.radTreeView1.FullRowSelect = true

    I am satisfied with this...
    Thank you very much for your help !

    Regards,
    Michael Pradier

    Reply

  • Answer Jordan Jordan admin's avatar

    Posted on Aug 29, 2008 (permalink)

    Hi Michael,

    I am glad to have been of service. Do not hesitate to write us back if you have more questions, suggestions or feedback.
     

    Best wishes,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Michal avatar

    Posted on Sep 21, 2011 (permalink)

    Hello!

    I am trying to disable node expanding/collapsing on double click. I came by this solution, however, it's no longer working with latest versions of Telerik(TreeNodeUI has been removed if I am correct). How should I proceed to solve this issue now?

    Cheers!
    Michal

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Avoid collapsing on double click
Related resources for "Avoid collapsing on double click"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]