2 ysc291064201 ysc291064201 于 2015.07.25 19:56 提问

winform中listview显示问题

为何第二次点击才显示第一次添加的内容
private void button7_Click(object sender, EventArgs e)
{
if (this.textBox7.Text == "" || this.textBox8.Text == "" || this.comboBox2.Text == "" || this.comboBox1.Text == ""
|| this.dateTimePicker5.Text == "" || this.comboBox3.Text == "" || this.textBox10.Text == "" || this.textBox11.Text == "")
{
MessageBox.Show("请将信息填写完整!");
return;
}
else
{
outpay pay = new outpay();
pay.ID = int.Parse(this.textBox7.Text);
pay.Money = int.Parse(this.textBox8.Text);
pay.PayWay = this.comboBox2.Text;
pay.PayType=this.comboBox1.Text;
pay.FromWhere=this.comboBox3.Text;
pay.PayTime = this.dateTimePicker5.Text;
pay.Owner=this.textBox10.Text;
pay.InFo=this.textBox11.Text;

            /*
            listView2.Items.Clear();
            foreach (outpay o in outPay)
            {
                string id = o.ID.ToString();
                ListViewItem lv = new ListViewItem(id);
                listView2.Items.Add(lv);
                lv.SubItems.AddRange(new string[] {o.Money.ToString(), o.PayType, 
                    o.PayWay,o.PayTime,o.FromWhere,o.Owner,o.InFo});
            */


             string[] str = new string[8];
             foreach (outpay o in outPay)
            {
                str[0] = this.textBox7.Text;
                str[1] = this.textBox8.Text;
                str[2] = this.comboBox2.Text;
                str[3] = this.comboBox1.Text;
                str[4] = this.dateTimePicker5.Text;
                str[5] = this.comboBox3.Text;
                str[6] = this.textBox10.Text;
                str[7] = this.textBox11.Text;
            ListViewItem item = new ListViewItem(str, 0);
            listView2.Items.Add(item);
            }

            outPay.Add(pay);
            SetOutPay();



            //button2_Click(sender, e);
            MessageBox.Show("添加成功!", "提示信息", 0, 0);
        }

1个回答

CSDNXIAOD
CSDNXIAOD   2015.07.25 20:08
已采纳

ListView的显示问题
关于Winform中listview的分页问题
WinForm显示效率问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片