private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { DisableControls(); TreeNodeTag nodeTag = e.Node.Tag as TreeNodeTag; if (nodeTag != null) { if (nodeTag.NodeType.IsValueType || nodeTag.Value is String) { if (nodeTag.PropertiesInfo.CanWrite) { ChosenNode = e.Node; propertyBox.Enabled = true; propertyButton.Enabled = true; if (nodeTag.Value is int) { numericUpDown.Value = (int)nodeTag.Value; numericUpDown.Enabled = true; } else if (nodeTag.Value is String) { textBox.Text = nodeTag.Value.ToString(); textBox.Enabled = true; } else if (nodeTag.Value is bool) { if ((bool)nodeTag.Value) { boolComboBox.SelectedIndex = 0; } else { boolComboBox.SelectedIndex = 1; } boolComboBox.Enabled = true; } else if (nodeTag.Value is double) { doubleBox.Text = nodeTag.Value.ToString(); doubleBox.Enabled = true; } else { foreach (var item in Enum.GetValues(nodeTag.Value.GetType())) { enumComboBox.Items.Add(item); if (item.Equals(nodeTag.Value)) { enumComboBox.SelectedIndex = enumComboBox.Items.IndexOf(item); } } enumComboBox.Enabled = true; } } } } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNodeTag nodeTag = e.Node.Tag as TreeNodeTag; selectedNode = nodeTag; if (nodeTag != null) { if (nodeTag.NodeType.IsValueType || nodeTag.Value is String) { choseNode = e.Node; textBox1.Text = nodeTag.Value.ToString(); textBox1.Visible = true; button1.Visible = true; } } }
private void button1_Click(object sender, EventArgs e) { if (choseNode != null) { TreeNodeTag nodeTag = (TreeNodeTag)choseNode.Tag; TreeNodeTag parentTag = (TreeNodeTag)choseNode.Parent.Tag; choseNode.Name = nodeTag.PropertiesInfo.Name + " = "; if (nodeTag.PropertiesInfo.CanWrite) { if (nodeTag.Value is int) { int value; if (int.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } else { MessageBox.Show("Incorrect input."); } } else { if (nodeTag.Value is String) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, textBox1.Text); nodeTag.Value = textBox1.Text; } else { if (nodeTag.Value is double) { double value; if (double.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } else { MessageBox.Show("Incorrect input"); } } else { if (nodeTag.Value is bool) { bool value; if (bool.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } } else { MessageBox.Show("Incorrect input"); } } } } } } textBox1.Visible = false; button1.Visible = false; treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); }
private void propertyButton_Click(object sender, EventArgs e) { if (ChosenNode != null) { TreeNodeTag nodeTag = (TreeNodeTag)ChosenNode.Tag; TreeNodeTag parentTag = (TreeNodeTag)ChosenNode.Parent.Tag; ChosenNode.Name = nodeTag.PropertiesInfo.Name + " = "; if (nodeTag.Value is int) { ChosenNode.Name += numericUpDown.Value.ToString(); nodeTag.PropertiesInfo.SetValue(parentTag.Value, (int)numericUpDown.Value); nodeTag.Value = numericUpDown.Value; } else if (nodeTag.Value is String) { ChosenNode.Name += textBox.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, textBox.Text); nodeTag.Value = textBox.Text; } else if (nodeTag.Value is bool) { if (boolComboBox.SelectedIndex == 0) { ChosenNode.Name += "True"; nodeTag.PropertiesInfo.SetValue(parentTag.Value, true); nodeTag.Value = true; } else { ChosenNode.Name += "False"; nodeTag.PropertiesInfo.SetValue(parentTag.Value, false); nodeTag.Value = false; } } else if (nodeTag.Value is double) { double temp; try { temp = double.Parse(doubleBox.Text); } catch { MessageBox.Show("Incorrect value"); return; } ChosenNode.Name += temp.ToString(); nodeTag.PropertiesInfo.SetValue(parentTag.Value, temp); nodeTag.Value = temp; } else { var item = enumComboBox.Items[enumComboBox.SelectedIndex]; ChosenNode.Name += item.ToString(); nodeTag.PropertiesInfo.SetValue(parentTag.Value, item); nodeTag.Value = item; } } DisableControls(); RefreshTree(); }