private void DeleteBtn_Click(object sender, EventArgs e) { int index = CmdList.SelectedIndex; if ((index >= 0) && (index <= CmdList.Items.Count - 1)) { DelCmdAt(index); if (CmdList.Items.Count > 0) { CmdList.SetSelected(CmdList.Items.Count - 1, true); } else { DeleteBtn.Enabled = false; } } }