Assuming that you have a button which should transfer selected items to another datagrid, you can use the following:
data source:
private DataTable _students;
private DataTable _topStudents;
private void Form1_Load(object sender, EventArgs e)
{
_students = new DataTable("Students");
_topStudents = new DataTable("TopStudents");
_topStudents.Columns.Add("name", typeof (string));
_students.Columns.Add("name", typeof(string));
_students.LoadDataRow(new object[] {"john"}, true);
_students.LoadDataRow(new object[] {"paul"}, true);
_students.LoadDataRow(new object[] {"jack"}, true);
dataGridViewSource.DataSource = _students;
dataGridViewTarget.DataSource = _topStudents;
}
copying selected rows:
private void buttonTransfer_Click(object sender, EventArgs e)
{
foreach (var row in dataGridViewSource.SelectedRows)
{
var dataRow = row as DataGridViewRow;
if (dataRow != null)
{
var values = ((DataRowView)dataRow.DataBoundItem).Row.ItemArray;
_topStudents.LoadDataRow(values, true);
}
}
}