I'm using TreeView
to control the permissions on my system, each operator has a profile that determines their minimum access, but it is possible to give more permissions to a particular operator, without having to create another profile example: inventory profile and inventory supervisor profile), but never remove a permission given by the profile.
For this I populated TreeView
using an object that extended the TreeNode
(list 1) class to which I added the Enabled
property that indicates whether the Checked
property can be changed. In the event BeforeCheck
of TreeView
(list 2) I check if the node is Enabled = false
and cancel the event. But by double clicking on the node it has its Checked
property changed, which hurts my restriction. I tried to cancel the DoubleClick
event of TreeView
, but method signature does not allow me to cancel the action.
In short: How do I cancel the double click action or prevent the Checked
property from being changed by it?
List 1
public class AccessNode : TreeNode
{
public AccessNode(string nome, string texto)
{
Name = nome;
Text = texto;
Checked = false;
}
public bool Enabled { get; set; } = true;
public void Propagate ()
{
/*propaga a alteração no "Cheked" para cima ou para baixo na arvore dependendo do nó atual*/
if (Checked)
CheckedParent();
else
UnCheckedNodes();
}
private void CheckedParent()
{
/*marca todos os nós do qual descende o nó atual, ou seja, pai, avô, bisavô, etc.*/
if (Parent != null)
{
Parent.Checked = true;
(Parent as AccessNode).CheckedParent();
}
}
private void UnCheckedNodes()
{
/*desmarca todos os nós decentendes do náo atual, ou seja, os filhos, os filhos dos filhos, etc.*/
foreach (TreeNode tn in Nodes)
tn.Checked = false;
}
}
List 2
private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e)
{
AccessNode an = e.Node as AccessNode;
e.Cancel = !an.Enabled;
}