For the button to move the records you can do so:
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 amount of selected records before entering for
, because Datagridview always selects the next element when one is eliminated... otherwise, what happens is that it ends up excluding everything from there down.
For double click 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 beforehand the data-Binding of each of the Datagridview. I created a Bindingsource for each grid.
EDIT
How to configure Bindingsource:
To fill in Bindingsource simply iterate the list elements and add them to 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 };
Po, but if you send as soon as you first click, how will you have reference to select multiples? The best would be to use a keyboard key to send as shortcut, and a... send button automatically on the first click becomes strange not?
– Miguel Angelo
To send multiple would hold Shift, I think I’ll leave with 2 clicks, so no error. Thanks for the remark Miguel
– William
@William as you are doing the Bind of the grid?
– Jéf Bueno
@jbueno, I’m using dgvGrupos.Datasource = bs_groups; Using the foreach of the list that Miguel passed, I was able to migrate the records from one grid to the other. I just need to make sure you don’t have a performance problem.
– William