I want to add items and values from form 2 to form 3 Listbox and show it accordingly in the form 3 labels.Final product should look like this form 2 adding the values and form 3 showing the value in menu and listbox accordingly I can add one item like the product name but I also want to add other aspects like price. So when I click on listbox in form 3 ,it should only show the names but in labels it should show the price aspect.
表格2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
string getItem = NameTextBox1.Text;
int getItem2 = Int32.Parse(PriceTxtBox2.Text);
var f = new Form3(getItem, getItem2);
f.Show();
}
表格3:
public partial class Form3 : Form
{
public Form3()
{
}
public struct Menu1
{
public string foodname;
public int foodprice;
}
public Form3(string title, int txt)
{
InitializeComponent();
List<Menu1> menulist = new List<Menu1>();
menulist.Add(new Menu1
{
foodname = title,
foodprice = txt
});
foreach (Menu1 details in menulist)
{
listBox1.Items.Add(String.Format(details.foodname));
listBox1.Items.Add(details.foodprice);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label4.Text = listBox1.SelectedItem.ToString();
label5.Text = listBox1.SelectedItem.ToString();
}
}
好像您没有连接到数据库,强烈建议您这样做。
但是按照您想要的方式,我想您可以