Hi,
Is there a way to restrict a RadTreeNode selection zone? In other words, I want to select/highlight a node only when the mouse is over the tree node name, and then not being able to select/highlight a node when the mouse is located in a blank space.
Regards.
Is there a way to restrict a RadTreeNode selection zone? In other words, I want to select/highlight a node only when the mouse is over the tree node name, and then not being able to select/highlight a node when the mouse is located in a blank space.
Regards.
4 Answers, 1 is accepted
0
Hi Nathalie,
Thank you for writing.
You will achieve this behavior if you set FullRowSelect property to "false". For example:
I hope this information helps. If you have further questions, feel free to write back
All the best,
Anton
the Telerik team
Thank you for writing.
You will achieve this behavior if you set FullRowSelect property to "false". For example:
this
.radTreeView1.FullRowSelect =
false
;
I hope this information helps. If you have further questions, feel free to write back
All the best,
Anton
the Telerik team
0
Nathalie
Top achievements
Rank 1
answered on 20 Nov 2012, 01:55 PM
Thanks for your answer.
My problem is I do not have the root node showing up in the tree view and I would like to get a general contextual menu while right-clicking in a blank space (and then no node is selected in the tree view).
When I right-click on a node name, I want its own contextual menu showing up (and not the general contextual menu).
Nathalie.
My problem is I do not have the root node showing up in the tree view and I would like to get a general contextual menu while right-clicking in a blank space (and then no node is selected in the tree view).
When I right-click on a node name, I want its own contextual menu showing up (and not the general contextual menu).
Nathalie.
0
Accepted
Hello Nathalie,
Thank you for writing back.
Here is how you can achieve the desired behavior:
1.Create your custom TreeViewControl that inherits RadTreeView.
2.Create a TreeViewElement that inherits RadTreeViewElement and override the ProcessContextMenu method with your custom logic. For example:
3. Use the MyCustomTreeViewControl to replace RadTreeView:
Attached is a sample project that comprises the code above. I hope this helps.
Let me know if this solution is not suitable for you.
Should you have any other questions, I will be glad to assist you.
All the best,
Anton
the Telerik team
Thank you for writing back.
Here is how you can achieve the desired behavior:
1.Create your custom TreeViewControl that inherits RadTreeView.
public
class
MyCustomTreeViewControl : RadTreeView
{
public
MyCustomTreeViewControl()
{
this
.ThemeClassName =
typeof
(RadTreeView).FullName;
}
protected
override
RadTreeViewElement CreateTreeViewElement()
{
return
new
MyCustomTreeViewElement();
}
}
2.Create a TreeViewElement that inherits RadTreeViewElement and override the ProcessContextMenu method with your custom logic. For example:
public
class
MyCustomTreeViewElement : RadTreeViewElement
{
protected
override
bool
ProcessContextMenu(Point location)
{
RadContextMenu defaultMenu =
new
RadContextMenu();
defaultMenu.Items.Add(
new
RadMenuItem(
"Item1"
));
defaultMenu.Items.Add(
new
RadMenuItem(
"Item2"
));
RadTreeNode node =
this
.GetNodeAt(location);
TreeNodeElement element =
this
.GetNodeElementAt(location.X, location.Y);
if
(node ==
null
)
{
defaultMenu.Show(
this
.ElementTree.Control, location);
}
else
{
if
(element.ContentElement.ControlBoundingRectangle.Contains(location))
{
node.ContextMenu.Show(
this
.ElementTree.Control, location);
}
else
{
defaultMenu.Show(
this
.ElementTree.Control, location);
}
}
return
true
;
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(RadTreeViewElement);
}
}
}
3. Use the MyCustomTreeViewControl to replace RadTreeView:
private
void
Form1_Load(
object
sender, EventArgs e)
{
RadTreeNode Node1 =
new
RadTreeNode(
"Node1"
);
RadTreeNode Node2 =
new
RadTreeNode(
"Node2"
);
RadTreeNode Node3 =
new
RadTreeNode(
"Node3"
);
RadTreeNode Node4 =
new
RadTreeNode(
"Node4"
);
this
.myTreeView.FullRowSelect =
false
;
this
.myTreeView.Nodes.Add(Node1);
this
.myTreeView.Nodes.Add(Node2);
Node1.Nodes.Add(Node3);
Node2.Nodes.Add(Node4);
RadContextMenu nodeMenu =
new
RadContextMenu();
nodeMenu.Items.Add(
new
RadMenuItem(
"NodeMenuItem1"
));
nodeMenu.Items.Add(
new
RadMenuItem(
"NodeMenuItem2"
));
Node1.ContextMenu = nodeMenu;
Node2.ContextMenu = nodeMenu;
}
Let me know if this solution is not suitable for you.
Should you have any other questions, I will be glad to assist you.
All the best,
Anton
the Telerik team
0
Nathalie
Top achievements
Rank 1
answered on 23 Nov 2012, 02:43 PM
Thank you very much. It works well!
Regards,
Nathalie.
Regards,
Nathalie.