private void lstInputs_DoubleClick(object sender, EventArgs e) { if (lstInputs.SelectedItems.Count == 1) { int itemHash = lstInputs.SelectedItems[0].GetHashCode(); ListViewItem listItem = lstInputs.SelectedItems[0]; SourceItem item = sourceItems[itemHash]; NameDialog dlgName = new NameDialog(); dlgName.NameText = item.Name; dlgName.SampleType = item.SampleType; dlgName.ShowDialog(); if (dlgName.DialogResult == DialogResult.OK) { item.Name = dlgName.NameText; item.SampleType = dlgName.SampleType; sourceItems.Remove(itemHash); int index = lstInputs.Items.IndexOf(listItem); lstInputs.Items.Remove(lstInputs.SelectedItems[0]); ListViewItem newItem = lstInputs.Items.Insert(index, new ListViewItem(item.GetStringValues())); sourceItems.Add(newItem.GetHashCode(), item); } } }
private void btnNewImage_Click(object sender, EventArgs e) { NameDialog dlgName = new NameDialog(); DialogResult r = dlgName.ShowDialog(this); if (r == DialogResult.OK) { Size itemSize = new Size(Convert.ToInt32(txtWidth.Text), Convert.ToInt32(txtHeight.Text)); SourceItem item = new SourceItem(itemSize, dlgName.SampleType, dlgName.NameText); ListViewItem newItem = lstInputs.Items.Add(new ListViewItem(item.GetStringValues())); sourceItems.Add(newItem.GetHashCode(), item); } if (lstInputs.SelectedItems.Count == 0 && lstInputs.Items.Count > 0) { lstInputs.Focus(); lstInputs.Items[0].Selected = true; } }