private void btnNew_Click(object sender, EventArgs e) { frmOptionEdit form = new frmOptionEdit("General", null); if (form.ShowDialog(this.ParentForm) == DialogResult.OK) { string[] subItems = new string[8]; subItems[0] = form.CurrentOption.VariableName; subItems[1] = form.CurrentOption.VarType.Name; subItems[2] = form.CurrentOption.Text; subItems[3] = form.CurrentOption.Description; for (int i = 0; i < form.CurrentOption.Values.Length; i++) { if (i > 0) { subItems[4] += ", "; } subItems[4] += form.CurrentOption.Values[i]; } subItems[5] = form.CurrentOption.Category; subItems[6] = form.CurrentOption.DefaultValue; subItems[7] = form.CurrentOption.IteratorType == null ? "" : form.CurrentOption.IteratorType.Name; ListViewItem item = new ListViewItem(subItems); lstOptions.Items.Add(item); Project.Instance.AddUserOption(form.CurrentOption); return; } }
private void PerformEdit() { if (lstOptions.SelectedItems.Count == 0) { return; } Cursor = Cursors.WaitCursor; string optionName = lstOptions.SelectedItems[0].SubItems[0].Text; int listIndex = lstOptions.SelectedIndices[0]; Project.UserOption currentOption = null; int index = -1; for (int i = 0; i < Project.Instance.UserOptions.Length; i++) { Project.UserOption option = Project.Instance.UserOptions[i]; if (option.VariableName == optionName) { index = i; currentOption = new Project.UserOption(option.VariableName, option.Category, option.VarType, option.Text, option.Description, option.Values, option.DefaultValue, option.IteratorType, option.ValidatorFunction, option.DefaultValueIsFunction, option.DisplayToUser, option.DisplayToUserIsFunction); break; } } frmOptionEdit form = new frmOptionEdit(currentOption); Cursor = Cursors.Default; if (form.ShowDialog(this.ParentForm) == DialogResult.OK) { string[] subItems = new string[9]; subItems[0] = form.CurrentOption.VariableName; subItems[1] = form.CurrentOption.VarType.Name; subItems[2] = form.CurrentOption.Text; subItems[3] = form.CurrentOption.Description; for (int i = 0; i < form.CurrentOption.Values.Length; i++) { if (i > 0) { subItems[4] += ", "; } subItems[4] += form.CurrentOption.Values[i]; } subItems[5] = form.CurrentOption.Category; subItems[6] = form.CurrentOption.DefaultValue; subItems[7] = form.CurrentOption.IteratorType == null ? "" : form.CurrentOption.IteratorType.Name; subItems[8] = form.CurrentOption.ValidatorFunction; ListViewItem item = new ListViewItem(subItems); lstOptions.BeginUpdate(); lstOptions.Items[lstOptions.SelectedItems[0].Index] = item; Project.Instance.UserOptions[index] = form.CurrentOption; Project.Instance.IsDirty = true; lstOptions.Items[listIndex].Selected = true; lstOptions.EndUpdate(); return; } }