I'm pretty new to VB and I'm having trouble with what seems like it should be a simple task. I have a datagridview that displays a number of rows - no problem. If I click on one of the rows (it's set up as full row select), the row is selected - again, no problem. What I want to happen is if I click on a row that has been selected, I want it to deselect the row. I know how to deselect by setting the selected parameter, but I'm not sure how to trigger the event and have it act on the correct row. I'd appreciate any help but please keep in mind that I have limited coding experience in VB. Thanks.
Asked
Active
Viewed 78 times
0
-
https://stackoverflow.com/a/4917947/14171304 – dr.null Nov 28 '22 at 21:03
-
vb.net version: https://stackoverflow.com/a/37327417/14171304 – dr.null Nov 28 '22 at 21:26
-
This isn't quite what I'm looking for. It works perfectly if you click on a different row - it selects the new row and deselectsif the old one. What I'm looking for is for the situation where you've selected a row in error. I want to be able to click on that row again and have it deselect. – Ross from Brooklin Nov 28 '22 at 23:37
-
I added the following code to see if the first piece is executing and it isn't. Could I have a setting wrong on the dgv? – Ross from Brooklin Nov 28 '22 at 23:53
-
' Fires first Private Sub dgvFiles_SelectionChanged(sender As Object, e As EventArgs) SelectionChanged = True MessageBox.Show("Executed") End Sub – Ross from Brooklin Nov 28 '22 at 23:55
-
I don't understand why the dgvFiles_CellClick event isn't being triggered. Can anyone help? Also, if I get it to trigger, how do I check the selected status of the row that was clicked? – Ross from Brooklin Nov 29 '22 at 01:33
-
You want to toggle selection, select and deselect a row on mouse click. Correct? Then the referred link is what you need to do. It's just like clicking a row while the `Ctrl` key is pressed. Both of which, toggle a row selection state. Not what you need? Then please clarify. – dr.null Nov 29 '22 at 08:37
-
I think I left out a key point - multiple selections are allowed. What I found the code in the sample does is toggle previous selections. For example. If I select row A, then B then C, and then decide I don't want C so I click on it again, it will deselect A and B and leave C selected. It works fine if there's just one item selected but not so well with multiple selections. – Ross from Brooklin Nov 29 '22 at 12:28
-
With `MultiSelect = true` and `SelectionMode = FullRowSelect`, when you Control + Click a Row, the Row is either selected or unselected, depending on its current state. It's not clear what kind of behavior you want instead – Jimi Nov 30 '22 at 23:15
-
Colour me stupid. That's exactly what I want to happen, but when I was doing my testing, I wasn't pressing the CTRL key. Thanks for the easies solution ever. – Ross from Brooklin Dec 01 '22 at 01:19