0
我正在嘗試打開並輸入列表標記。輸入通過一個類接收,附加到一個字符串值,然後添加到列表中。然而,我不能讓這份清單工作。使用列表中的列表填充列表框
public class Deliveries
{
private string customername;
public string CustName
{
get { return customername; }
set { customername = value; }
}
private string customeraddress;
public string CustAddress
{
get { return customeraddress; }
set { customeraddress = value; }
}
public DateTime deliverytime;
public DateTime DelTime
{
get { return deliverytime; }
set { deliverytime = value; }
}
public string output;
private void ToString()
{
output=deliverytime.ToString() + " " + CustName + " " + CustAddress;
}
}
該列表存儲在一個名爲Lists的獨立類中。
class Lists
{
private List<Deliveries> deliveries = new List<Deliveries>();
public void addDelivery(Deliveries del)
{
deliveries.Add(del);
}
public List<String> listDeliveries()
{
List<String> listDeliveries = new List<string>();
foreach (Deliveries del in deliveries)
{
String delAsString = del.ToString();
listDeliveries.Add(delAsString);
}
return listDeliveries;
}
public Deliveries getDelivery(int index)
{
int count = 0;
foreach (Deliveries del in deliveries)
{
if (index == count)
return del;
count++;
}
return null;
}
最後,應該將它添加到列表框的代碼,存儲在窗體的Load
listBox1.Items.Clear();
List<String> delList = ListOut.listDeliveries();
listBox1.Items.AddRange(delList.ToArray());
目前,它不添加任何。任何幫助將不勝感激
檢入調試器中有多少項ListOut.listDeliveries();將在頁面加載時返回 – SergeyS
它返回0 –
請將代碼發佈到您創建並填充ListOut的位置。 – SergeyS