'is there a code in c# that loads all the elements filled using an array, into the listbox I have once my form is loaded?
I'm working with Microsoft visual studio 2022 C#, doing a windows application form.( Currently new, been practicing for a month) I came across this question :
When the form is loaded, the product list box will be filled with each product array element. ( Previously I used to make a button that once clicked loads all the elements but this is the first practice exercise I come across and its relat5ed to the form)
( I filled the products in the listbox using the List method as but I cant seem to make them load into the listbox once i open the form. How do I solve this issue?
Thats how i filled the product using the lists method
List prod = new List()
what i tried: creating a Display Class then call it the form1 code part but I struggled upon an error and that didnt work as shown below
private void Form1_Load(object sender, EventArgs e)
{
DisplayProducts();
}
private void DisplayProducts()
{
AllProducts.Items.Clear();
AllProducts.Items.AddRange(prod.ToArray());
}
The error is in AllProducts So I changed it into Products then the Items gave me an error CS0117 is the type of the error I have tried everything it still gives me an error . Is there something I'm missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
