【发布时间】:2012-12-04 23:51:31
【问题描述】:
我有一个项目正在努力解决如何从列表中删除。
我要删除的列表项是用户从列表框中选择的索引中的任何项。
该项目有一个名为 Pickcuplist 的列表类和 2 个 GUI,一个用于主窗体,一个用于拾取窗体。拾取表单是删除按钮所在的位置,但带有选定索引的列表框位于主表单上。
我找到了 List.RemoveAt 但是我似乎无法让它工作。
物品被添加到列表中,就像从拾取表单中一样:
txtCustName.Text = thePickup.name;
txtCustAddress.Text = thePickup.address;
txtArrival.Text = thePickup.arrival.ToString();
txtDaddress.Text = thePickup.Daddress;
txtDeliveryName.Text = thePickup.Dname;
LblType.Text = thePickup.type;
这是主表单添加的代码
/*
* This method creates a new pickup object, allows the user to
* enter details and adds it to the List
*
*/
Pickupform.pickup = new Pickups();
//New Visit- note added to the pickupform object
Pickupform.ShowDialog();
//Show the pickupForm. ShowDialog ensures that the form has the exclusive focus until it is closed.
if (Pickupform.pickup != null)
//if null then the "cancel" button was pressed
{
Pickups newpic = Pickupform.pickup;
//Get the Pickup object from the form
thePickup.addPickups(newpic);
//Add the visit to the list
}
updateList();
//Update the list object to reflect the Pickups in the list
【问题讨论】:
-
我看不到您要删除的位置...
-
RemoveAt到底有什么不好的地方? -
移除物品的代码在哪里?
-
如果你想删除一个项目,你需要一个 thePickup.RemoveAt(index)。
-
@TAM 那行代码 (
theList.listVisits().RemoveAt(int index);) 不是有效的 C#,它甚至还不够接近有效,无法知道从哪里开始纠正它。在继续之前,您可能需要复习基本的 C# 编程概念和语法。