public static DatabaseViewerItem CreateFromUnityObject(List <string> stuff) { DatabaseViewerItem newItem = new DatabaseViewerItem(); newItem.children = new List <TreeViewItem>(); newItem.depth = 0; newItem.properties = new string[stuff.Count]; for (int i = 0; i < stuff.Count; i++) { newItem.properties[i] = stuff[i]; } return(newItem); }
protected override TreeViewItem BuildRoot() { // BuildRoot is called every time Reload is called to ensure that TreeViewItems // are created from data. Here we create a fixed set of items. In a real world example, // a data model should be passed into the TreeView and the items created from the model. // This section illustrates that IDs should be unique. The root item is required to // have a depth of -1, and the rest of the items increment from that. var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" }; root.parent = null; root.children = new List <TreeViewItem>(); while (reader.Read()) { List <string> cellValues = new List <string>(); for (int i = 0; i < reader.FieldCount; i++) { cellValues.Add(reader[i].ToString()); } DatabaseViewerItem item = DatabaseViewerItem.CreateFromUnityObject(cellValues); //item.icon = //item.id = GetNewID(); root.children.Add(item); } // Utility method that initializes the TreeViewItem.children and .parent for all items. //SetupDepthsFromParentsAndChildren(root); //SetupParentsAndChildrenFromDepths (root, root.children); //SetupDepthsFromParentsAndChildren(root); // Return root of the tree return(root); }