Beispiel #1
0
        public NewModPropNewForm(NewModForm modform, ListViewItem listViewItem)
        {
            InitializeComponent();
            Modform             = modform;
            WorkingListViewItem = listViewItem;

            // Clears all items inside of GroupComboBox.
            GroupComboBox.Items.Clear();
            // Adds all groups from the ListView into GroupComboBox.
            foreach (ListViewGroup group in modform.GetListView().Groups)
            {
                GroupComboBox.Items.Add(group.Header);
            }

            // Adds "Add Group" to GroupComboBox so the user can create groups.
            GroupComboBox.Items.Add("Add Group");
            GroupComboBox.SelectedIndex = 0;

            Text = "New Property";

            if (listViewItem != null)
            {
                Text                        = "Edit Property";
                label1.Text                 = "Edit Property: " + listViewItem.Text;
                TypeComboBox.Text           = listViewItem.Tag as string;
                textBox1.Text               = listViewItem.Text;
                GroupComboBox.SelectedIndex = modform.GetListView().Groups.IndexOf(listViewItem.Group);
                AddButton.Text              = "Update";
                ValueTextBox.Select();

                UpdateType();

                // Parses the text.
                switch (listViewItem.Tag)
                {
                case "Integer":
                    if (listViewItem.SubItems[1].Text.Length > 0)
                    {
                        ValueNumericUpDown.Value = int.Parse(listViewItem.SubItems[1].Text);
                    }
                    break;

                case "Boolean":
                    if (listViewItem.SubItems[1].Text.Length > 0)
                    {
                        ValueCheckBox.Checked = bool.Parse(listViewItem.SubItems[1].Text);
                    }
                    break;

                default:
                    ValueTextBox.Text = listViewItem.SubItems[1].Text.Replace("\\n", "\r\n");
                    break;
                }
            }
        }
Beispiel #2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            if (GroupComboBox.SelectedItem as string == "Add Group")
            {
                if (textBox1.Text.Length > 0)
                {
                    GroupComboBox.Items.Add(Modform.AddGroup(textBox1.Text).Header);
                    GroupComboBox.SelectedIndex = GroupComboBox.Items.Count - 1;
                    GroupComboBox.Items.Remove("Add Group");
                    GroupComboBox.Items.Add("Add Group");
                }
                return;
            }
            if (WorkingListViewItem != null)
            {
                switch (TypeComboBox.Text)
                {
                case "Integer":
                    WorkingListViewItem.SubItems[1].Text = ValueNumericUpDown.Value.ToString();
                    break;

                case "Boolean":
                    WorkingListViewItem.SubItems[1].Text = ValueCheckBox.Checked.ToString();
                    break;

                default:
                    WorkingListViewItem.SubItems[1].Text = ValueTextBox.Text;
                    break;
                }
                WorkingListViewItem.Text  = textBox1.Text;
                WorkingListViewItem.Tag   = TypeComboBox.Text;
                WorkingListViewItem.Group = Modform.GetListView().Groups[GroupComboBox.SelectedIndex];
            }
            else
            {
                switch (TypeComboBox.Text)
                {
                case "Integer":
                    Modform.AddProperty(textBox1.Text, ValueNumericUpDown.Value.ToString(),
                                        GroupComboBox.SelectedIndex, TypeComboBox.Text);
                    break;

                case "Boolean":
                    Modform.AddProperty(textBox1.Text, ValueCheckBox.Checked.ToString(),
                                        GroupComboBox.SelectedIndex, TypeComboBox.Text);
                    break;

                default:
                    Modform.AddProperty(textBox1.Text, ValueTextBox.Text, GroupComboBox.SelectedIndex,
                                        TypeComboBox.Text);
                    break;
                }
            }

            Close();
        }