C#窗体中用户填写的信息如何如在listview中显示?
private void button2_Click(object sender, EventArgs e)
{
em[count] = new work();
em[count].ename = textBox1.Text;
em[count].eno = textBox2.Text;
em[count].eage = textBox3.Text;
em[count].ephone = textBox4.Text;
em[count].edate = dateTimePicker1.Text;
if (radioButton1.Checked == true)
em[count].esex = radioButton1.Text;
else
em[count].esex = radioButton2.Text;
em[count].ephoto = pictureBox1.ImageLocation;
for(int i=0;i<count;i++)
{
ListViewItem lv =new ListViewItem();
lv.Text=em[i].eno;
lv.SubItems.Add(em[i].ename);
lv.SubItems.Add(em[i].esex);
lv.SubItems.Add(em[i].eage);
lv.SubItems.Add(em[i].edate);
lv.SubItems.Add(em[i].ephone);
lv.SubItems.Add(em[i].ephoto);
listView1.Items.Add(lv);
count++;
}
我的代码,运行问题是“System.StackOverflowException”类型的未经处理的异常出现在 餐厅.exe 中。
------解决方案--------------------
for(int i=0;i<count;i++)
{
ListViewItem lv =new ListViewItem();
lv.Text=em[i].eno;
lv.SubItems.Add(em[i].ename);
lv.SubItems.Add(em[i].esex);
lv.SubItems.Add(em[i].eage);
lv.SubItems.Add(em[i].edate);
lv.SubItems.Add(em[i].ephone);
lv.SubItems.Add(em[i].ephoto);
listView1.Items.Add(lv);
count++;
}
你这个for循环中,不停地count++,你永远也跳不出这个循环了吧,i<count能满足吗