private TreeGridNode AddNode(ManagementBaseObject o, PropertyData p, TreeGridNodeCollection nodes) { TreeGridNode node = nodes.Add(p.Name, p.GetValueAsString(this.valueMaps)); string guid = GetGUID(); node.Tag = guid; this.objectMap.Add(guid, o); this.propertyMap.Add(guid, p); // Get property description var description = String.Empty; if (this.ManagementClass != null && this.managementClass.HasProperty(p.Name)) { description = this.ManagementClass.Properties[p.Name].GetDescription(); if (!String.IsNullOrEmpty(description)) { description = "\r\n" + description; } } // Set tooltip node.Cells[0].ToolTipText = String.Format( "{0} {1}.{2}{3}", p.Type.ToString() + (p.IsArray ? "[]" : String.Empty), this.ManagementObject.ClassPath.ClassName, p.Name, description ); // Highlight key columns if (p.IsKey()) { // Apply styles Font f = node._grid.DefaultCellStyle.Font; node.Cells[0].Style.Font = new Font(f.FontFamily, f.Size, FontStyle.Bold); } // Expand arrays if (p.Value != null && p.IsArray) { var values = p.GetValueAsStringArray(this.ShowMappedValues ? this.valueMaps : null); int i = 0; bool addValues = true; foreach (object value in values) { if (i >= MAX_ARRAY_MEMBERS) { addValues = false; } else { // Keep add values or just count them? if (addValues) { TreeGridNode child = node.Nodes.Add(String.Format("[{0}]", i), value.ToString()); child.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; child.Cells[0].Style.ForeColor = SystemColors.GrayText; } i++; } } // Add note if results were truncated if (!addValues) { TreeGridNode truncNode = node.Nodes.Add(String.Format("[...{0}]", i), "Results were truncated."); truncNode.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; truncNode.Cells[0].Style.ForeColor = SystemColors.GrayText; } node.Cells[1].Value = String.Format("{0} [{1}]", p.Type, i); } // Expand Objects if (p.Type == CimType.Reference || p.Type == CimType.Object) { if (p.Value != null) { // TODO: What about object arrays? ManagementBaseObject refObject; if (p.Type == CimType.Reference && null != this.Scope) { refObject = new ManagementObject(this.Scope, new ManagementPath((String)p.Value), new ObjectGetOptions()); } else { refObject = (ManagementBaseObject)p.Value; } node.Cells[1].Value = refObject.GetRelativePath(); foreach (PropertyData subProperty in refObject.Properties) { TreeGridNode subNode = this.AddNode(refObject, subProperty, node.Nodes); string subGuid = GetGUID(); subNode.Tag = subGuid; this.objectMap.Add(subGuid, refObject); this.propertyMap.Add(subGuid, subProperty); } } else { node.Cells[1].Value = "NULL"; } } return(node); }