首页 > 解决方案 > Form1 DataGridView 复制到 Form2 DataGridView

问题描述

我试图在datagridview中选择一行单击创建然后它将该行的特定单元格复制到form2(不制作新表单或覆盖现有数据),基本上就像采购订单一样。我可以用 2 个 Datagridviews 在同一个表单上做我需要做的事情

           //THIS WORKS FOR DATAGRIDVIEWS ON SAME FORM//
        if (this.dataGridView2.DataSource != null)
         {
             this.dataGridView2.DataSource = null;
         }
          else
         {
           // this.dataGridView2.Rows.Clear();
         }
         for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
         {
             int index = dataGridView2.Rows.Add();
            dataGridView2.Rows[index].Cells[0].Value = dataGridView1.SelectedRows[i].Cells[5].Value.ToString();
             dataGridView2.Rows[index].Cells[1].Value = dataGridView1.SelectedRows[i].Cells[2].Value.ToString();

             dataGridView2.Rows[index].Cells[0].Value = dataGridView1.SelectedRows[i].Cells[5].Value.ToString();
             dataGridView2.Rows[index].Cells[1].Value = dataGridView1.SelectedRows[i].Cells[2].Value.ToString();

但是当 Form2 上有相同的控件时将不起作用。我需要它以这种方式工作,但传输(复制)到 FrmMetalKit(Form2)

这是图像从 Main Form1 到 FrmMetalKit (Form2) 的样子

标签: c#datagridview

解决方案


推荐阅读