목록의 항목을 채우려 고 시도하고 List <의 항목으로 채우려 고 다른 형식으로 호출하려고합니다. 그러나 그것은 다른 형태로 하중을 가하는 것처럼 보이지 않습니다. 어떤 도움을 주셔서 감사합니다. List <> C#
private void frmAdminMenu_Load(object sender, EventArgs e)
{
Product prod1 = new Product(001, "Milk", "Dairy", 1.20m, 10, 1.027m);
Product prod2 = new Product(002, "Cheese", "Dairy", 2.80m, 20, 0.300m);
Product prod3 = new Product(003, "Apple", "Fruit", 0.50m, 10, 0.136m);
Product prod4 = new Product(004, "Orange", "Fruit", 0.80m, 20, 0.145m);
Product prod5 = new Product(005, "Tomato", "Veg", 2.50m, 15, 0.110m);
Product prod6 = new Product(006, "Onion", "Veg", 1.50m, 10, 0.105m);
Product prod7 = new Product(007, "Lamb", "Meat", 4.50m, 10, 0.340m);
Product prod8 = new Product(008, "Chicken", "Meat", 3.50m, 10, 0.907m);
products.Add(prod1);
products.Add(prod2);
products.Add(prod3);
products.Add(prod4);
products.Add(prod5);
products.Add(prod6);
products.Add(prod7);
products.Add(prod8);
FillProductListBox();
}
private void FillProductListBox()
{
lstViewStock.Items.Clear();
foreach (Product p in products)
{
lstViewStock.Items.Add(p.GetDisplayText("\t"));
}
}
이 내가
listbox.DataSource = something;
공지 사항 목록 상자에 표시 있으며, toString 메소드의 구현을 사용하는 예제를 만들어 또 다른 형태의
ListBox tmpProducts;
public frmEnterShop()
{
InitializeComponent();
}
List<Product> shoppingCart = new List<Product>();
public frmEnterShop(ListBox shippedIn)
: this()
{
tmpProducts = shippedIn;
MessageBox.Show("Total of " + tmpProducts.Items.Count, "Number of Items"); // view-Output
}
private void frmEnterShop_Load(object sender, EventArgs e)
{
lstViewProducts.Items.Add(tmpProducts.Items[0]);
lstViewProducts.Items.Add(tmpProducts.Items[1]);
lstViewProducts.Items.Add(tmpProducts.Items[2]);
lstViewProducts.Items.Add(tmpProducts.Items[3]);
lstViewProducts.Items.Add(tmpProducts.Items[4]);
lstViewProducts.Items.Add(tmpProducts.Items[5]);
lstViewProducts.Items.Add(tmpProducts.Items[6]);
lstViewProducts.Items.Add(tmpProducts.Items[7]);
}
* 참고 :'frmEnterShop_Load'에서 수행하는 작업은'for' 루프에 있어야합니다. –