我一直想寫一個虛擬店一所學校的項目,並已遇到問題轉換所選項目到我Shoppingcart
清單選擇列表框項目轉換成一個列表C#
public class shoppingcart
{
public int cost;
public int id;
public string name;
public void setCost(int c)
{
cost = c;
}
public void setId(int i)
{
id = i;
}
public void setname(string n)
{
name = n;
}
public void getCost(int c)
{
}
public void getId(int i)
{
}
public void getname(string n)
{
}
}
public List<shoppingcart> Shoppingcart = new List<shoppingcart>();
//An example of what my objects look like incase this helps
//Experiment
shoppingcart ghostitem = new shoppingcart();
ghostitem.setname("");
ghostitem.setCost(0);
ghostitem.setId(0);
Shoppingcart.Add(ghostitem);
private void addCart_Click(object sender, EventArgs e)
{
try
{
totalitems = totalitems + 1;
for (int i = 0; i < MeleeItem.Count(); i++)
{
Shoppingcart.Add(meleeList.SelectedItems);
}
}
catch
{
}
}
你在列表框中顯示? –
您是否嘗試調試並查看以下類型:meleeList.SelectedItems – iYonatan
列表框顯示對象的名稱。我希望能夠將所選對象轉移到購物車列表中,然後查找我爲特定對象設置的成本 – Firelord190