Also where do you change the color of the selected background?
Thanks
3 Answers, 1 is accepted
Thank you for writing.
You can cancel the selection with right mouse button in the RadTreeView SelectedNodeChanging event using the following code:
void
radTreeView1_SelectedNodeChanging(
object
sender, RadTreeViewCancelEventArgs e)
{
if
(Control.MouseButtons == MouseButtons.Right)
{
e.Cancel =
true
;
}
}
void
radTreeView1_MouseDown(
object
sender, MouseEventArgs e)
{
if
(e.Button == MouseButtons.Right)
{
RadElement element =
this
.radTreeView1.ElementTree.GetElementAtPoint(e.Location);
if
(!(element
is
TreeNodeElement))
{
element = element.FindAncestor<TreeNodeElement>();
}
if
(element
as
TreeNodeElement !=
null
)
{
((TreeNodeElement)element).DrawFill =
true
;
((TreeNodeElement)element).BackColor = Color.Red;
}
}
}
void
radTreeView1_NodeFormatting(
object
sender, TreeNodeFormattingEventArgs e)
{
e.NodeElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.NodeElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
I hope this will be useful for you. If you need further assistance, I would be glad to help. All the best,
Ivan Petrov
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.
Private m_lstSelectedNodes As New List(Of RadTreeNode)
Private
Sub
rtvTest_SelectedNodeChanged(sender
As
Object
, e
As
Telerik.WinControls.UI.RadTreeViewEventArgs)
Handles
rtvTask.SelectedNodeChanged
If
Control.MouseButtons <> Windows.Forms.MouseButtons.Left
Then
For
Each
rtvnNode
As
RadTreeNode
In
m_lstSelectedNodes
rtvnNode.Selected =
True
Next
m_lstSelectedNodes.Clear()
End
If
End
Sub
Private
Sub
rtvTest_SelectedNodeChanging(sender
As
Object
, e
As
Telerik.WinControls.UI.RadTreeViewCancelEventArgs)
Handles
rtvTest.SelectedNodeChanging
If
Control.MouseButtons = Windows.Forms.MouseButtons.Right
Then
m_lstSelectedNodes.Clear()
For
Each
rtvnNode
As
RadTreeNode
In
rtvTask.SelectedNodes
m_lstSelectedNodes.Add(rtvnNode)
Next
e.Cancel =
True
End
If
End
Sub
Thank you for sharing your solution.
The solution you have came up with is perfectly legal with only one minor draw back - the memory you need for the selected nodes collection you have to keep and the triggering of the selection events again. When you set the Selected property of a node, you trigger all the events that follow a selection, involving the events in which you trigger it.
I hope this will be useful for you. Should you need further assistance, feel free to write back.
Ivan Petrov
the Telerik team
Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.