为什么删除时我的列表会像队列一样?哪个列表框中有“约会”并不重要,添加的第一个“约会”始终是第一个“约会”被删除。
List<Appointment> appointmentList = new List<Appointment>();
以下是我的删除按钮的片段:
private void btnDeleteApp_Click_1(object sender, EventArgs e)
{
if ((!(appointmentList.Count > 0)) || (lstDayView.SelectedIndex == -1 && listBox1.SelectedIndex == -1 && listBox2.SelectedIndex == -1 && listBox3.SelectedIndex == -1 &&
listBox4.SelectedIndex == -1 && listBox5.SelectedIndex == -1 && listBox6.SelectedIndex == -1 && listBox7.SelectedIndex == -1 && listBox8.SelectedIndex == -1 &&
listBox9.SelectedIndex == -1 && listBox10.SelectedIndex == -1 && listBox11.SelectedIndex == -1 && listBox12.SelectedIndex == -1 && listBox13.SelectedIndex == -1 &&
listBox14.SelectedIndex == -1 && listBox15.SelectedIndex == -1 && listBox16.SelectedIndex == -1 && listBox17.SelectedIndex == -1 && listBox18.SelectedIndex == -1 &&
listBox19.SelectedIndex == -1 && listBox20.SelectedIndex == -1 && listBox21.SelectedIndex == -1 && listBox22.SelectedIndex == -1 && listBox23.SelectedIndex == -1 &&
listBox24.SelectedIndex == -1 && listBox25.SelectedIndex == -1 && listBox26.SelectedIndex == -1 && listBox27.SelectedIndex == -1 && listBox28.SelectedIndex == -1 &&
listBox29.SelectedIndex == -1 && listBox30.SelectedIndex == -1 && listBox31.SelectedIndex == -1 && listBox32.SelectedIndex == -1 && listBox33.SelectedIndex == -1 &&
listBox34.SelectedIndex == -1 && listBox35.SelectedIndex == -1 && listBox36.SelectedIndex == -1 && listBox37.SelectedIndex == -1 && listBox38.SelectedIndex == -1 &&
listBox39.SelectedIndex == -1 && listBox40.SelectedIndex == -1 && listBox41.SelectedIndex == -1 && listBox42.SelectedIndex == -1))
{
MessageBox.Show("Error! You need to make and/or select an appointment!");
return;
}
else
if (MessageBox.Show("Are you sure you wish to delete?", "Confirm Delete", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
if (lstDayView.SelectedIndex != -1)
{
appointmentList.RemoveAt(lstDayView.SelectedIndex); //Issue this is removed the index number from the list not the appointmentList
this.setCal();
}
else if (listBox1.SelectedIndex != -1)
{
appointmentList.RemoveAt(listBox1.SelectedIndex);
this.setCal();
}
else if (listBox2.SelectedIndex != -1)
{
appointmentList.RemoveAt(listBox2.SelectedIndex);
this.setCal();
}
else if (listBox3.SelectedIndex != -1)
{
appointmentList.RemoveAt(listBox3.SelectedIndex);
this.setCal();
}
答案 0 :(得分:0)
在大多数列表框中,一旦选择了一个项目,说服它选择0项是后面的痛苦。
单步执行事件处理程序,您应该看到这一点。