private void AddNewTaskDescription(object sender, EventArgs e) { if (treeView.SelectedNode != null) { NewTaskDescriptionDialog ntdd = new NewTaskDescriptionDialog(treeView.SelectedNode.Tag as TaskDescription); if (ntdd.ShowDialog(this) == DialogResult.OK) { TaskDescription taskDescription = new TaskDescription { Id = Guid.NewGuid(), Name = ntdd.TaskDescription.Name, Color = ntdd.TaskDescription.Color, NoNagMinutes = ntdd.TaskDescription.NoNagMinutes, IsEvent = false }; TreeNode treeNode = new TreeNode(taskDescription.Name) { Tag = taskDescription }; if ((treeView.SelectedNode.Tag != null) && (treeView.SelectedNode.Tag.GetType() == typeof(TaskDescription))) { if (treeView.SelectedNode.Tag is TaskDescription td) { td.Children.Add(taskDescription); treeView.SelectedNode.Nodes.Add(treeNode); treeView.SelectedNode = treeNode; } } else { treeView.Nodes[0].Nodes.Add(treeNode); treeView.SelectedNode = treeNode; ((Collection <TaskDescription>)treeView.Nodes[0].Tag).Add(taskDescription); } AppContext.Current.TaskDescriptionsProvider.SaveDescriptions(); } } }
private void AddNewTaskDescription(object sender, EventArgs e) { if (treeView.SelectedNode != null) { NewTaskDescriptionDialog ntdd = new NewTaskDescriptionDialog(treeView.SelectedNode.Tag as TaskDescription); if (ntdd.ShowDialog(this) == DialogResult.OK) { TaskDescription taskDescription = new TaskDescription(); taskDescription.Id = Guid.NewGuid(); taskDescription.Name = ntdd.TaskDescription.Name; taskDescription.Color = ntdd.TaskDescription.Color; taskDescription.NoNagMinutes = ntdd.TaskDescription.NoNagMinutes; taskDescription.IsEvent = false; TreeNode treeNode = new TreeNode(taskDescription.Name); treeNode.Tag = taskDescription; if ((treeView.SelectedNode.Tag != null) && (treeView.SelectedNode.Tag.GetType() == typeof(TaskDescription))) { TaskDescription td = treeView.SelectedNode.Tag as TaskDescription; if (td != null) { td.Children.Add(taskDescription); treeView.SelectedNode.Nodes.Add(treeNode); treeView.SelectedNode = treeNode; } } else { treeView.Nodes[0].Nodes.Add(treeNode); treeView.SelectedNode = treeNode; ((Collection<TaskDescription>)treeView.Nodes[0].Tag).Add(taskDescription); } AppContext.Current.TaskDescriptionsProvider.SaveDescriptions(); } } }