在我下面的代码中,我有一个 AccessId 列表,它存储在树节点的标记中。如何检查它们的标签在我的列表中的节点(或子节点)?
List<AccessFieldSet> AccessList = new List<AccessFieldSet>();
private void GetRolesAccessData(Int32 RolesId)
{
C_RolesUsers Db = new C_RolesUsers();
AccessList = Db.GetRolesAccessData(RolesId);
foreach (AccessFieldSet Afs in AccessList)
{
foreach (TreeNode node in TreeRoles.Nodes)
{
if (node.Tag == Afs.AccessId.ToString())
{
//Check Node is true ?
}
GetTagChildren(node);
}
}
}
private void GetTagChildren(TreeNode Node)
{
TreeNode ChNode = null;
//TreeFieldSet nodeCat = (TreeFieldSet)Node.Tag;
//Int32 nodeCat = (Int32)Node.Tag;
foreach (AccessFieldSet Afs in AccessList)
{
if (Afs.AccessId.ToString() == Node.Tag)
{
//Check Node is true ?
GetTagChildren(ChNode);
}
}
}
我将代码编辑为:
List<AccessFieldSet> AccessList = new List<AccessFieldSet>();
private void GetRolesAccessData(Int32 RolesId)
{
C_RolesUsers Db = new C_RolesUsers();
AccessList = Db.GetRolesAccessData(RolesId);
for (int i = 0; i < TreeRoles.Nodes.Count; i++)
{
CheckedSelectedNodes(i, TreeRoles.Nodes, AccessList);
}
}
private void CheckedSelectedNodes(Int32 i, TreeNodeCollection nodes, List<AccessFieldSet> AccessList)
{
TreeNode node = nodes[i];
for (int j = 0; j < AccessList.Count; j++)
{
foreach (AccessFieldSet Afs in AccessList)
{
if ((int)node.Tag == Afs.AccessId)
{
node.Checked = true;
}
}
}
}
使用新代码,我可以检查节点标记在 AccessList 中的节点。如何更改 ChildNodes(节点的孩子)的代码?