This is a migrated thread and some comments may be shown as answers.

Avoid collapsing on double click

9 Answers 388 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 27 Aug 2008, 11:47 AM
Hello,

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

Regards,
Michael

9 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 27 Aug 2008, 02:17 PM
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.


0
Michael
Top achievements
Rank 1
answered on 27 Aug 2008, 03:59 PM
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
0
Jordan
Telerik team
answered on 28 Aug 2008, 07:40 AM
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.
0
Michael
Top achievements
Rank 1
answered on 28 Aug 2008, 12:23 PM
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
0
Accepted
Michael
Top achievements
Rank 1
answered on 28 Aug 2008, 02:36 PM
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
0
Accepted
Jordan
Telerik team
answered on 29 Aug 2008, 11:43 AM
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.
0
Michal
Top achievements
Rank 1
answered on 21 Sep 2011, 01:47 PM
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
0
Bradley Lane
Top achievements
Rank 1
answered on 27 Sep 2012, 10:12 PM
You can use the ToggleMode property to setup the Single/Double Click functionality:



radTreeView1.ToggleMode = ToggleMode.SingleClick;
0
Stefan
Telerik team
answered on 29 Sep 2012, 10:42 AM
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
Tags
Treeview
Asked by
Michael
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Michael
Top achievements
Rank 1
Michal
Top achievements
Rank 1
Bradley Lane
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or