ysc291064201
cheetah--y
采纳率100%
2015-07-25 11:56 阅读 2.2k

winform中listview显示问题

20

为何第二次点击才显示第一次添加的内容
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);
        }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐