/// <summary> /// Click on the "Delete" button. It delete the selected animation group. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteAnimationButton_Click(object sender, EventArgs e) { int selectedIndex = animationListBox.SelectedIndex; if (selectedIndex < 0) { return; } AnimationGroup selectedItem = (AnimationGroup)animationListBox.SelectedItem; // delete item selectedItem.DeleteFromData(); // update list animationGroups.Remove(selectedItem); animationGroups.SaveToData(); animationListBinding.ResetBindings(false); // get new selected item at the current index, if any selectedIndex = Math.Min(selectedIndex, animationListBox.Items.Count - 1); selectedItem = selectedIndex < 0 ? null : (AnimationGroup)animationListBox.Items[selectedIndex]; animationListBox.SelectedItem = selectedItem; }