[C#] 纯文本查看 复制代码 private void GetCheckedOfficeID(TreeListNode parentNode, List<int> lstCheckedOfficeID)
{
if (parentNode.Nodes.Count == 0)
{
return;//递归终止
}
foreach (TreeListNode node in parentNode.Nodes)
{
if (node.CheckState == CheckState.Checked)
{
object o = this.treeList1.GetDataRecordByNode(node);
int OfficeID = ((Employee)node.Tag).IDS; //初始状态下将Tag属性设置为节点绑定的数据源
lstCheckedOfficeID.Add(OfficeID);
}
GetCheckedOfficeID(node,lstCheckedOfficeID);
}
}
public List<int> GetTreeNodesIDS(TreeList treelist)
{
List<int> plists=new List<int>();
if (treelist.Nodes.Count > 0)
{
foreach (TreeListNode root in treelist.Nodes)
{
GetCheckedOfficeID(root,plists);
}
}
return plists;
}
调用方式:
List<int> poids = GetTreeNodesIDS(treeList1);
通过遍历获取节点进行操作 |