单元格值更改时如何将一行从datagridview复制到另一个datagridview

时间:2019-02-04 13:03:13

标签: c#

当我对第一个datagridview1数据进行更改时,我想复制,然后只想将更改后的行数据从datagridview1复制到datagridview2

private void button1_Click(object sender, EventArgs e) {

        string query = @"Select Item.ItemName as item, Stock.SalePrice as 
        Price, invoice.Qty 
        FROM invoice
        JOIN item ON invoice.ItemID = item.ItemID
        JOIN sale ON invoice.SaleID = sale.SaleID
        join Stock on Stock.ItemID  = item.ItemID 
        where sale.SaleID = '" + textBox1.Text + "'";
        SqlDataAdapter SDA = new SqlDataAdapter(query, con);
        DataTable dt = new DataTable();
        SDA.Fill(dt);
        dataGridView1.DataSource = dt;


        DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
        dataGridView1.Columns.Add(btn);
        btn.HeaderText = "Update";
        btn.Text = "Update";
        btn.Name = "btnUpdate";
        btn.UseColumnTextForButtonValue = true;
}

我称之为单元格值更改事件,但该代码仅复制已编辑的行。

请提供我代码:

1 个答案:

答案 0 :(得分:0)

CellValueChanged的{​​{1}}事件中尝试此操作,

datagGridview1

希望这对您有帮助...