Rob Sherratt
Well-known member
Hope others will find this "Tip" useful (even though it's from a "newBie") ...
Double clicking a DataGridView object within Forms Designer generates the following Click event handler:
One "problem" with the default event handler is that it only responds to cell clicks if the cell in MyDataGridView is populated and the user happens to click EXACTLY on the text. There can be a problem with mouse alignment here!
IMHO, a better cell click event to use is this:
It has "better behaviour" for many user applications. Whenever the user clicks anywhere in the cell region the selection focus is changed and the CellClick event is generated immediately afterwards.
The cell co-ordinates in both cases are provided inside the Click event "e As DataGridViewCellEventArgs" instance as follows:
Regards,
Rob
Double clicking a DataGridView object within Forms Designer generates the following Click event handler:
VB.NET:
Private Sub MyDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles MyDataGridView.CellContentClick
End Sub
One "problem" with the default event handler is that it only responds to cell clicks if the cell in MyDataGridView is populated and the user happens to click EXACTLY on the text. There can be a problem with mouse alignment here!
IMHO, a better cell click event to use is this:
VB.NET:
Private Sub MyDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles MyDataGridView.CellClick
End Sub
It has "better behaviour" for many user applications. Whenever the user clicks anywhere in the cell region the selection focus is changed and the CellClick event is generated immediately afterwards.
The cell co-ordinates in both cases are provided inside the Click event "e As DataGridViewCellEventArgs" instance as follows:
VB.NET:
MySelectedRow = e.RowIndex
MySelectedCol = e.ColumnIndex
Regards,
Rob
Last edited: