我有一個項目,我正在努力如何從列表中刪除。RemoveAt index c#
我想要刪除的列表項目是用戶從列表框中選擇的索引處的任何項目。
該項目有一個名爲Pickcuplist的列表和一個用於主窗體的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
我看不到你要刪除的位置... – Chris
究竟是不是有關'RemoveAt'的工作? –
去除物品的代碼在哪裏? – ChrisF