private void buttonEdit_Click(object sender, EventArgs e) { if (myListView.FocusedItem == null) { MessageBox.Show("You did not choose an item"); return; } int n = myListView.FocusedItem.Index; ItemAdd editform = new ItemAdd(false); editform.ShowDialog(); myListView.Items.RemoveAt(n); ListViewItem item = new ListViewItem(""); if (editform.cbItem.Text == "not selected") { item = new ListViewItem(editform.textBoxName.Text); } else { item = new ListViewItem(editform.cbItem.Text); } item.SubItems.Add(editform.textBoxPrice.Text); item.SubItems.Add(editform.dateTimePiDate.Value.ToShortDateString().ToString()); if (editform.textBoxPrice.ForeColor == Color.Red) { item.BackColor = Color.Red; } myListView.Items.Insert(n, item); }
private void button_Add_Click(object sender, EventArgs e) { ItemAdd itemadd = new ItemAdd(true); if (itemadd.ShowDialog() == DialogResult.OK) { ListViewItem item = new ListViewItem(""); if (itemadd.cbItem.Text == "not selected") { item = new ListViewItem(itemadd.textBoxName.Text); } else { item = new ListViewItem(itemadd.cbItem.Text); } item.SubItems.Add(itemadd.textBoxPrice.Text); item.SubItems.Add(itemadd.dateTimePiDate.Value.ToShortDateString().ToString()); if (itemadd.textBoxPrice.ForeColor == Color.Red) { item.BackColor = Color.Red; } myListView.Items.Add(item); } }