Avoid collapsing on double click

10 posts, 2 answers
  1. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2008

    Posted 27 Aug 2008 Link to this post

    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
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 27 Aug 2008 Link to this post

    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.


  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2008

    Posted 27 Aug 2008 Link to this post

    <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
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 28 Aug 2008 Link to this post

    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.
  6. Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2008

    Posted 28 Aug 2008 Link to this post

    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
  7. Answer
    Michael
    Michael avatar
    6 posts
    Member since:
    Aug 2008

    Posted 28 Aug 2008 Link to this post

    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
  8. Answer
    Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 29 Aug 2008 Link to this post

    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.
  9. Michal
    Michal avatar
    4 posts
    Member since:
    Sep 2011

    Posted 21 Sep 2011 Link to this post

    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
  10. Bradley Lane
    Bradley Lane avatar
    22 posts
    Member since:
    Aug 2012

    Posted 27 Sep 2012 Link to this post

    You can use the ToggleMode property to setup the Single/Double Click functionality:



    radTreeView1.ToggleMode = ToggleMode.SingleClick;
  11. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 29 Sep 2012 Link to this post

    Hi,

    That is correct, you can control the expanding/collapsing when a node is clicked by using the ToggleMode property of TreeViewElement. It has three options:

    • Single - the node will expand/collapse on single click.
    • Double - the node will expand/collapse on double click.
    • None - the node will not expand/collapse on click.
    radTreeView1.TreeViewElement.ToggleMode = Telerik.WinControls.UI.ToggleMode.None;

    @Bradley - your Telerik Points have been update for the community effort.

    I hope that the provided information addresses your question. If there is anything else we can assist you with, do not hesitate to contact us.

    Best wishes,
    Stefan
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready