I have a Datagrid with a CheckBox column. I need to select more than one row from this datagrid and get the SelectedRows to another form. What I need is that when I check the checkboxes all the checked rows must still selected (blue hightlight) until I pass them to the another form. I can do it now, but just for one row, the selected one with this code
private void button2_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
table.Columns.Add(column.Name, typeof(string)); //tipo cell??
}
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
table.Rows.Add();
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
table.Rows[i][j] = dataGridView1.SelectedRows[i].Cells[j].Value;
fph.dataGridView1.DataSource = table; //DATAGRID DO FORM PH
}
}
}
thank you all!
Clicking one an item selects it and deselets all others. This is standard behaviour. The obvious way to go within the GUI standards is to educate your users to press control if they don't want to lose their current selection, just like they have to anywhere else in the system.
If you don't like that, you will have either find some weird trick or on each CellMouseDown check if this is the Checkbox column and then store the selected rows and restore the selection on CellMouseUp. (or something like this, no time here to test this for you..)