Exemplo n.º 1
0
        public void Display <T>(CrmComponentCollection <T> compCollection, CrmTreeNode <T> childNode) where T : CrmComponent
        {
            foreach (var kv in compCollection.Properties)
            {
                lvComponents.Columns.Add(new ColumnHeader()
                {
                    Text = kv.Value
                });
            }
            foreach (var comp in compCollection.Components)
            {
                ListViewItem item = null;
                int          i    = 0;
                foreach (var kv in compCollection.Properties)
                {
                    if (i == 0)
                    {
                        item     = new ListViewItem(comp.GetPropertyValue(kv.Key)?.ToString());
                        item.Tag = comp;
                        lvComponents.Items.Add(item);
                        item.Name = comp.Name;
                    }
                    else
                    {
                        item.SubItems.Add(comp.GetPropertyValue(kv.Key)?.ToString());
                    }
                    i++;
                }
            }
            lvComponents.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            for (int j = 0; j < lvComponents.Columns.Count; j++)
            {
                var col = lvComponents.Columns[j];
                col.Width = col.Width < 150 ? 150 : col.Width;
            }

            if (childNode != null)
            {
                var nodeToSelect = lvComponents.Items.Find(childNode.Name, false);
                if (nodeToSelect.Length > 0)
                {
                    nodeToSelect[0].Selected = true;
                }
            }
        }
Exemplo n.º 2
0
        public void AddRootNode <T>(CrmSolution crmSol, string itemName, string collectionName, string displayName, CrmComponentCollection <T> collection, int imgIdx) where T : CrmComponent
        {
            var rootNode = new CrmTreeNode <T>()
            {
                Component = new CrmComponent()
                {
                    Text = displayName
                },
                Tag        = collectionName,
                ImageIndex = imgIdx,
                Collection = collection
            };

            tree.Nodes.Add(rootNode);
            foreach (var c in collection.Components)
            {
                var d = (CrmComponent)c;
                var n = new CrmTreeNode <T>()
                {
                    Component  = c,
                    Tag        = itemName,
                    ImageIndex = imgIdx,
                    Name       = c.Name
                };
                rootNode.Nodes.Add(n);
            }
        }