Reputation: 861
How do I make it so my code selects the rows in the data grid view that they click rather than hard coding it into the code itself, I want to select each row that the user selects with the mouse on the form.
Upvotes: 0
Views: 213
Reputation: 586
You have to set multiselect to true for your DataGridView and your dataGridView.SelectionMode should be FullRowSelect
Example:
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.MultiSelect = true;
Then you can get the selected rows with
Dim selectedItems As DataGridViewSelectedRowCollection = dataGridView.SelectedRows
For Each selectedItem As DataGridViewRow In selectedItems
'Add code to handle whatever you want for each row
Next
End Sub
Upvotes: 2