private void lvSpells_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { pnlSpell.Controls.Clear(); if (e.IsSelected && !_creating) { var editor = new SpellEditor(this, e.Item.Text); pnlSpell.Controls.Add(editor); } }
private void lvSpells_AfterLabelEdit(object sender, LabelEditEventArgs e) { bool sort = false; if (string.IsNullOrEmpty(e.Label)) { e.CancelEdit = true; if (_creating) lvSpells.Items.RemoveAt(e.Item); } else { if (_renaming) { var oldName = lvSpells.Items[e.Item].Text; RenameSpell(oldName, e.Label); } SpellEditor editor = new SpellEditor(this, e.Label); editor.Dock = DockStyle.Fill; pnlSpell.Controls.Clear(); pnlSpell.Controls.Add(editor); sort = true; } _renaming = false; _creating = false; // this will execute after the method ends (i.e. after the label has been committed) if (sort) lvSpells.BeginInvoke(new MethodInvoker(lvSpells.Sort)); }