如何编辑另一个表单中的listview项目

时间:2015-11-26 14:03:44

标签: c#

on form1上的调整数量按钮我有

    private void button1_Click(object sender, EventArgs e)
    {
        adjust fr = new adjust();
        int i = 0;
        ListViewItem it = listView1.SelectedItems[i];
        it.Remove();
        string v1 = it.SubItems[1].Text;
        decimal v2 = decimal.Parse(it.SubItems[2].Text);
        decimal v3 = decimal.Parse(it.SubItems[3].Text);
        fr.itemcodetxt.Text = v1;
        fr.currentquantity.Text = v2.ToString();
        fr.pricetxt.Text = v3.ToString();

        fr.ShowDialog();


    }

并在form2上(调整)我有这个代码

    private void button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        Form1 f = new Form1();


        //Is the error i recieve here
        ListViewItem item = f.listView1.Items[1]; //Additional information: InvalidArgument=Value of '1' is not valid for 'index'.
        string itemcode = item.SubItems[1].Text;
        decimal itemquantity = decimal.Parse(item.SubItems[2].Text);
        decimal pr = decimal.Parse(item.SubItems[3].Text);
        decimal totalp = decimal.Parse(item.SubItems[2].Text) * decimal.Parse(textBox1.Text);
        totalp = decimal.Parse(item.SubItems[4].Text);

        var itm = new ListViewItem();
        item.Text = "1";
        item.SubItems.Add(itemcodetxt.Text);
        item.SubItems.Add(textBox1.Text);
        item.SubItems.Add(pr.ToString());
        item.SubItems.Add(totalp.ToString());

        f.listView1.Items.Add(item);

    }

0 个答案:

没有答案