public void CreateModel(ProjectController project, bool randomizeData) { try { TreeNode fNode = null; foreach (TreeNode nn1 in treeView1.Nodes) { if (nn1.Tag.Equals(project.GetGuid())) { fNode = nn1; break; } else { fNode = fromID(project.GetGuid(), nn1); } } // string guid = Guid.NewGuid().ToString(); var modelName = $"Model{fNode.Nodes.Count}"; //create model project.Project.DataSet = expPanel1.GetDataSet(); project.CreateModel(guid, modelName, randomizeData); //expand tree item and select it var tn = createTreeNode(guid, modelName, 2); fNode.Nodes.Add(tn); tn.Expand(); treeView1.SelectedNode = tn; } catch (Exception ex) { ReportException(ex); } }