How do I use my Form’s constructor to populate a Listbox with data from an Array in C#? So far this is what I have in my Name Class
String[,] strSpecialCakeName = {
{"Holiday Cake at", "$18"},
{"Birthday Cake at", "$25"},
{"Wedding Cake at", "$40"},
{"Super Hero Cake at", "$30"}
};
And this is what I have in my Form
public partial class frmLabSeven : Form
{
private string[,] strSpecialCakeName = new string[4, 2];
public frmLabSeven()
{
InitializeComponent();
strSpecialCakeName [0, 0] = "Holiday Cake at $18";
strSpecialCakeName [1, 1] = "Birthday Cake at $25";
strSpecialCakeName [2, 2] = "Wedding Cake at $40";
strSpecialCakeName [3, 3] = "Super Hero Cake at $30";
}
}
I know I can use the Collection in Item right on the Form, but that is not what I want to do. I just don’t know how to get the data to show on the List Box using Arrays.
First thing you need to be aware of is that your array looks like this:
You can use a for statement to add it to your listbox: