首页 文章

在c#中将数据从一个gridview传递到另一个gridview

提问于
浏览
1

我在不同的形式使用两个网格视图,我想传递form1所有单元格值另一个Form [form2] . form2数据 view in one cell . 然后单击form2单元格加载form1单元格中的所有数据视图 .

这个form1 - >

private void button1_Click(object sender, EventArgs e)
    {

        string[] colB = new string[dataGridView1.Rows.Count];

        for (int i = 0; i < dataGridView1.Rows.Count -1; i++)
        {
            colB[i] = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);

        }
    }

如何获取数据form2->?

1 回答

  • 0

    表单是与其他类似的类 . 但是,它们具有从 Form 类继承的特定于窗口的行为 .

    这意味着您可以指定自己的构造函数并传递您想要的任何信息 . 例如,假设我们要在新表单中显示Person类 . 我们可以定义一个新的 PersonForm 来显示细节(这只是一个例子 . 您将能够根据您的需要进行调整) .

    public class PersonForm : Form 
    {
        PersonForm(Person model)
        {
            InitializeComponents(); //I think this is the name of the method.
    
            //Do whatever is needed here with the model.
        }
    }
    

    因此,当用户双击右侧单元格时,您将创建 PersonForm 的新实例并显示它 .

相关问题