0

我有 2listviewsdatagridview.

一个列表视图有 3 列ProductCode,ProductName,ProductPrice,第二个列表视图有两列Godown Name,Godown Code

当我单击datagridview' 的第一列时,product我想要listview visible并且我想将listview' 的选定值以datagridview相同的顺序传递给 。

当我单击godowndatagridview 中的列时,应该godown listview变得可见,然后将选定的值传递godown listview给. 我怎样才能做到这一点?godowndatagridview

在此处输入图像描述

4

1 回答 1

0

以下是一些可能有帮助的代码:

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
        for (int i = 1; i < listView1.Items.Count; i++)
        {
            dataGridView1.Rows.Add();
        }

    }

    private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        //Decide which column corresponds to the one clicked
        switch (e.ColumnIndex)
        {
            case 0:
                FillColumn(listView2, 0, e.ColumnIndex);
                break;
            case 1:
                FillColumn(listView1, 1, e.ColumnIndex);
                break;
            case 2:
                FillColumn(listView2, 1, e.ColumnIndex);
                break;
            case 3:
                FillColumn(listView1, 0, e.ColumnIndex);
                break;
            case 4:
                FillColumn(listView1, 2, e.ColumnIndex);
                break;
        }
    }
    //Take the corresponding listview, the listview column, and the dgv column
    //and populate the dgv with the listview data
    private void FillColumn(ListView lv, int lvcolumn, int dgvcolumn)
    {
        lv.Visible = true;            
        foreach (ListViewItem lvi in lv.Items)
        {
            dataGridView1.Rows[lvi.Index].Cells[dgvcolumn].Value = lvi.SubItems[lvcolumn].Text;
        }
    }
}
于 2013-07-07T08:41:13.260 回答