获取ListView的同一行上的多个列的值

时间:2017-04-10 12:46:09

标签: c# forms winforms listview

我有一个ListView表,我希望用户能够在表中选择一个值并单击编辑,这将打开另一个表单供他们编辑。传递变量和第四个并重新填充表的最佳方法是什么?

这是我到目前为止所做的:

private void editSelected_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < basket.Items.Count; i++)
        {
            if (basket.Items[i].Selected)
            {
                string product = //get product string from table
                string quantity = //get quantity string from table
                string price = //get price string from table
            }
        }
    }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

像这样,为避免异常,您应将#button { position: fixed; top: 30px; right: 20px; } 设置为false,

MultiSelect

Form1(您的主要表单包含listView1.MultiSelect = false; ),

ListView

编辑表单背后的代码看起来像;

public ListView _ListView {
     get { return this.listView1; }
}
private void button1_Click(object sender, EventArgs e){
    Form2 frm = new Form2(this);
    frm.productName = listView1.Items[listView1.SelectedItems[0].Index].SubItems[0].Text; // set defined variable value (for example, index of subitems 0 represents ProductName)
    frm.Show();    
}

希望有所帮助,