private void buttonEdit_Click(object sender, EventArgs e) { ListViewItem selectedItem = listView.SelectedItems[0]; Session session = (Session)selectedItem.Tag; using (EditSessionDialog dialog = new EditSessionDialog()) { if (dialog.ShowDialog(this, session) == DialogResult.OK) { SetListViewItem(selectedItem, session); PendingChanges = true; } } }
private void buttonNew_Click(object sender, EventArgs e) { Session session = new Session(); session.Start = DateTime.Now; session.Category = SessionCategory.New; using (EditSessionDialog dialog = new EditSessionDialog()) { if (dialog.ShowDialog(this, session) == DialogResult.OK) { sessions.Add(session); RefreshListView(); // Select the newly created item for (int i = 0; i < listView.Items.Count; i++) { ListViewItem item = listView.Items[i]; if (object.ReferenceEquals(item.Tag, session)) { item.Selected = true; item.EnsureVisible(); break; } } PendingChanges = true; } } }