DataGridView中并没有显示克隆行后的数据并没有、数据、DataGridView

2023-09-06 17:44:52 作者:饮一场孤酒

Windows窗体应用程序。 C#4.0。

Windows form application. C# 4.0.

基本上我有两个datagridviews dgv1和dgv2。一个正确显示表。我想选择和克隆从dgv1一些行通过点击细胞dgv1到dgv2。

Basically I have two datagridviews dgv1 and dgv2. One displays the table correctly. I want to select and clone some rows from dgv1 to dgv2 by clicking on the cells in dgv1.

但第二个根本不显示数据。

But the second one doesn't show data at all.

   DataTable dt = new DataTable();
   dgv2.AutoGenerateColumns = true;
   private void btnAdd_Click(object sender, EventArgs e)
   {
        DataRowView currentDataRowView = (DataRowView)dgv1.CurrentRow.DataBoundItem;
        DataRow row = currentDataRowView.Row;
        // add row
        dt.ImportRow(row);
        dgv2.DataSource = dt;
    }

在调试模式下,我所发现的是,

In debug mode, what I found is that

        ?dt.Rows.Count
        1
        ?dt.Columns.Count
        0
        ?dgv2.AutoGenerateColumns
        true

感谢您的咨询。

Thanks for advice.

推荐答案

您必须创建列或从另一个表复制的模式!

You must create your columns or copy the schema from another table!