For the move button you can do the following:
var selectedRowCount = dataGridView1.SelectedRows.Count;
if (selectedRowCount > 0)
for (int i = 0; i < selectedRowCount; i++)
{
var obj = dataGridView1.SelectedRows[0].DataBoundItem;
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
pessoaBindingSource2.Add(obj);
}
Note that I had to store the number of records selected before entering for
, because the DataGridView always selects the next element when one is deleted ... otherwise, what happens is that it ends up being excluded everything down.
For double clicking it is much easier:
if (dataGridView1.SelectedRows.Count == 1)
{
var obj = dataGridView1.SelectedRows[0].DataBoundItem;
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
pessoaBindingSource2.Add(obj);
}
It is necessary to configure the data-binding of each of the DataGridView beforehand. I created a BindingSource for each grid.
EDIT
How to configure BindingSource:
To populate the BindingSource, simply iterate through the elements of the list and add them to the BindingSource:
foreach (var item in minhaLista)
pessoaBindingSource1.Add(item);
Or so, as my interlocutor taught me in one of the comments:
new BindingSource() { DataSource = lista };