advtree复制选中项
public static void CopySelectTree(DevComponents.AdvTree.NodeCollection n1, DevComponents.AdvTree.NodeCollection n2)
{
n2.Clear();
List> list = null;
GetSelect(n1, ref list);
for (int i = 0; i < list.Count; i++)
{
List list2 = list[i];
foreach (DevComponents.AdvTree.Node _nd in list2)
{
DevComponents.AdvTree.Node[] node3 = n2.Find(_nd.Name, true);
if (node3.Length == 0)
{
if (_nd.Parent == null) { n2.Add(CreateNode(_nd.Name, _nd.Text, _nd.Tag, _nd.Checked)); }
else
{
DevComponents.AdvTree.Node[] node4 = n2.Find(_nd.Parent.Name, true);
if (node4.Length > 0)
{
node4[0].Nodes.Add(CreateNode(_nd.Name, _nd.Text, _nd.Tag, _nd.Checked));
}
}
}
}
}
}
public static DevComponents.AdvTree.Node CreateNode(string _name, string _text, object tag, bool b = false)
{
DevComponents.AdvTree.Node node = new DevComponents.AdvTree.Node();
node.CheckBoxVisible = true;
node.Name = _name;
node.Text = _text;
node.Checked = b;
node.Tag = tag;
return node;
}
public static DevComponents.AdvTree.Node CreateNode(DevComponents.AdvTree.Node _node)
{
DevComponents.AdvTree.Node node = new DevComponents.AdvTree.Node();
node.CheckBoxVisible = _node.CheckBoxVisible;
node.Name = _node.Name;
node.Text = _node.Text;
node.Checked = _node.Checked;
node.Tag = _node.Tag;
return node;
}
public static void GetSelect(DevComponents.AdvTree.NodeCollection n1, ref List> list)
{
if (list == null) { list = new List>(); }
for (int i = 0; i < n1.Count; i++)
{
if (n1[i].Checked)
{
List list2 = GetParent(n1[i]);
list.Add(list2);
}
GetSelect(n1[i].Nodes, ref list);
}
}
public static List GetParent(DevComponents.AdvTree.Node node)
{
List list = new List();
list.Add(CreateNode(node));
while (node.Parent != null)
{
node = node.Parent;
list.Add(CreateNode(node));
}
list.Reverse();
return list;
}
使用方法
DevComponents.AdvTree.NodeCollection nodes = new NodeCollection();
CopySelectTree(advTree_2019.Nodes, nodes);