我有一个项目正在努力解决如何从列表中删除的问题。
我要删除的列表项是用户从列表框中选择的索引中的任何项。
该项目有一个名为 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