Is it possible to override the tristate to allow for Any node to be in a 3 phase status?
I am working on a security module and the categories that are available to a user will appear in the treeview (all fine and dandy), but there is going to be 3 security modes associated with each litem, Deny, View, or Edit and three phase will work perfectly for this, but the current implementation only seems to allow for a Parent node to be in an intermediary state.
Can this be overridden to allow for Each node to just have independent control of the three values, to then read and set my security levels?
4 Answers, 1 is accepted
0
Accepted
Hello,
Thank you for writing.
By default, RadTreeView supports tri-state mode for its nodes automatically. Hence, when one of the child nodes is checked but the others aren't, the parent node's state is ToggleState.Indeterminate. In order to customize the checkboxes and allow three states for each node, you can create a custom RadTreeNode, override its CheckState property and don't propagate the status change to its children/parents. Additionally, in the NodeFormatting event, it is necessary to enable the three states for each node element. Here is a sample code snippet:
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik
Thank you for writing.
By default, RadTreeView supports tri-state mode for its nodes automatically. Hence, when one of the child nodes is checked but the others aren't, the parent node's state is ToggleState.Indeterminate. In order to customize the checkboxes and allow three states for each node, you can create a custom RadTreeNode, override its CheckState property and don't propagate the status change to its children/parents. Additionally, in the NodeFormatting event, it is necessary to enable the three states for each node element. Here is a sample code snippet:
public
Form1()
{
InitializeComponent();
this
.radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
for
(
int
i = 0; i < 5; i++)
{
CustomTreeNode node =
new
CustomTreeNode() { Text =
"Node"
+ i };
for
(
int
j = 0; j < 3; j++)
{
CustomTreeNode subNode =
new
CustomTreeNode() { Text =
"SubNode"
+ i +
"."
+ j };
node.Nodes.Add(subNode);
}
this
.radTreeView1.Nodes.Add(node);
}
this
.radTreeView1.CheckBoxes =
true
;
this
.radTreeView1.TriStateMode =
true
;
}
private
void
radTreeView1_NodeFormatting(
object
sender, TreeNodeFormattingEventArgs e)
{
((RadCheckBoxElement)e.NodeElement.ToggleElement).IsThreeState =
true
;
}
public
class
CustomTreeNode : RadTreeNode
{
public
override
Telerik.WinControls.Enumerations.ToggleState CheckState
{
get
{
return
base
.CheckState;
}
set
{
this
.SetCheckStateCore(value);
}
}
}
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Support
Top achievements
Rank 1
answered on 11 May 2016, 12:56 PM
Thanks for that code, works perfectly..But now I also want to
“re-implement” the functionality of checking all children with the parent
state.
I added a recursion of a function to recurse after the CheckState Changed, ant it works if traced through, but at full speed, it basically gets one state off for all the children…
If there another method or event to cancel to allow this to happen properly?
Thanks
Class RadTriStateNode
Inherits RadTreeNode
Public Overrides Property CheckState As Telerik.WinControls.Enumerations.ToggleState
Get
Return MyBase.CheckState
End Get
Set(value As Telerik.WinControls.Enumerations.ToggleState)
Me.SetCheckStateCore(value)
CheckUncheckTreeNode(Me.Nodes, value)
End Set
End Property
Private Sub CheckUncheckTreeNode(trNodeCollection As RadTreeNodeCollection, CheckedState As Telerik.WinControls.Enumerations.ToggleState)
For Each trNode As RadTriStateNode In Me.Nodes
trNode.SetCheckStateCore(Me.CheckState)
Next
End Sub
End Class
I added a recursion of a function to recurse after the CheckState Changed, ant it works if traced through, but at full speed, it basically gets one state off for all the children…
If there another method or event to cancel to allow this to happen properly?
Thanks
Class RadTriStateNode
Inherits RadTreeNode
Public Overrides Property CheckState As Telerik.WinControls.Enumerations.ToggleState
Get
Return MyBase.CheckState
End Get
Set(value As Telerik.WinControls.Enumerations.ToggleState)
Me.SetCheckStateCore(value)
CheckUncheckTreeNode(Me.Nodes, value)
End Set
End Property
Private Sub CheckUncheckTreeNode(trNodeCollection As RadTreeNodeCollection, CheckedState As Telerik.WinControls.Enumerations.ToggleState)
For Each trNode As RadTriStateNode In Me.Nodes
trNode.SetCheckStateCore(Me.CheckState)
Next
End Sub
End Class
0
Support
Top achievements
Rank 1
answered on 11 May 2016, 04:54 PM
Actually you can close this now. I replaced that code with overriding the OnCheckStatusChanges(checkedMode as CheckedMode) routine and added the
For Each trNode As RadTriStateNode In Me.Nodes
trNode.SetCheckStateCore(Me.CheckState)
Next
Code within it and that seemed to work.
Thanks
For Each trNode As RadTriStateNode In Me.Nodes
trNode.SetCheckStateCore(Me.CheckState)
Next
Code within it and that seemed to work.
Thanks
0
Hello,
Thank you for writing back.
I am glad that the problem you were facing is now resolved. However, you can find below a sample code snippet demonstrating how to set the ToggleState of a child node considering the parent node's state:
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
Thank you for writing back.
I am glad that the problem you were facing is now resolved. However, you can find below a sample code snippet demonstrating how to set the ToggleState of a child node considering the parent node's state:
public
class
CustomTreeNode : RadTreeNode
{
public
override
Telerik.WinControls.Enumerations.ToggleState CheckState
{
get
{
return
base
.CheckState;
}
set
{
if
(
this
.CheckState != value)
{
this
.SetCheckStateCore(value);
this
.TreeView.BeginUpdate();
CheckUncheckTreeNode(
this
.Nodes, value == ToggleState.Indeterminate ? ToggleState.Off : ToggleState.On);
this
.TreeView.EndUpdate();
}
}
}
private
void
CheckUncheckTreeNode(RadTreeNodeCollection trNodeCollection, Telerik.WinControls.Enumerations.ToggleState checkedState)
{
foreach
(CustomTreeNode trNode
in
this
.Nodes)
{
trNode.SetCheckStateCore(checkedState);
}
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.