开发者

Transfer of Databound Datagridview Row To Another Datagridview

开发者 https://www.devze.com 2023-03-20 17:15 出处:网络
I have a two datagridview as datagridview1 datagridview2 datagridview1 has a checkbox columns which check the rowindex and transfer the same row to another datagridview2

I have a two datagridview as

datagridview1

datagridview2

datagridview1 has a checkbox columns which check the rowindex and transfer the same row to another datagridview2

datagridview1 is a databound开发者_如何学Go control and having columns as below:

checkbox Column,Name and Amount

where as datagridview2 also having same column accept checkbox column.

I wants to transfer data of datagridview1.selected rows to another datagridview2 by click on checkbox column.

How to do?.


You can do that by handling CellContentClick event of DataGridView. Then you check if check box column was clicked, get current row and import it into another DataGridView. Here is what I mean:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
            if (e.ColumnIndex == myCheckBoxColumnName.Index) {
                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                string name = row.Cells["Name"].Value.ToString();
                string amount = row.Cells["Amount"].Value.ToString();
                dataGridView2.Rows.Add(name, amount);
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消