Пример #1
0
        public void AddLayer(LayerCollection collectionLayer)
        {
            // disable events temporarily
            treeView1.AfterCollapse -= treeView1_AfterCollapse;
            treeView1.AfterExpand   -= treeView1_AfterExpand;

            treeView1.Nodes.Clear();

            TreeNode        groupNode  = null;
            List <TreeNode> groupNodes = new List <TreeNode>();

            foreach (LayerGroup layerGroup in collectionLayer.OrderByDescending(elm => elm.Position))
            {
                var group = groupNodes.FirstOrDefault(elm => elm.Text == layerGroup.Group.Name);
                if (group == null)
                {
                    // group toevoegen
                    groupNode = new TreeNode(layerGroup.Group.Name);
                    groupNodes.Add(groupNode);

                    if (layerGroup.Group.Expanded)
                    {
                        groupNode.Expand();
                    }
                }

                // layer toevoegen
                TreeNode layerNode = new TreeNode();
                layerNode.Text    = layerGroup.Name;
                layerNode.Checked = layerGroup.LayerVisible;
                layerNode.Tag     = layerGroup.Handle;

                groupNode.Nodes.Add(layerNode);
            }

            treeView1.Nodes.AddRange(groupNodes.ToArray());

            // Enable events again
            treeView1.AfterCollapse += treeView1_AfterCollapse;
            treeView1.AfterExpand   += treeView1_AfterExpand;
        }