【发布时间】:2016-01-31 19:24:00
【问题描述】:
我有两个表格,表格 1 和表格 2。
form1 有 3 个按钮,button1(vanilla)、button2(chocolate) 和 button3(nextpage)
form2 有一个 listView1
当用户点击香草3次和巧克力1次时,我想在form2的listView1的数量列中显示“3”和“1”。
下面有截图。
form1
public partial class form1 : Form
{
private string vanilla = "Vanilla";
private string chocolate= "Chocolate";
private List<string> _values= new List<string>();
public form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
if (!_values.Contains(vanilla))
{
_values.Add(vanilla);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!_values.Contains(chocolate))
{
_values.Add(chocolate);
}
}
private void button3_Click(object sender, EventArgs e)
{
form2 form2 = new form2(_values);
form2.Show();
this.Hide();
}
}
form2
public partial class form2 : Form
{
public form2(List<string> passedValues)
{
InitializeComponent();
foreach(var item in passedValues)
{
listView1.Items.Add(item);
}
}
}
它应该在香草排显示 3 个,在巧克力排显示 1 个
【问题讨论】: