Hello all,
I am using th following code to determine the row clicked in a DataGrid:
The problem comes when there are more rows than can be displayed in the visible portion of the grid. Say there are 5 rows, but only 3 of them are fully visible, the fourth is half-visible (half of the row is obscured) and the fifth row is not visible at all without scrolling. If I click on rows 1-3, there is no problem. But if I click on row 4 while it is still partially obscured by the botom of the grid, then "hit.Row" returns -1 and the code "sender.select(hit.Row)" throws an "Index was outside the bounds of the array" error. If I scroll such that the 4th row is fully visible then everything is ok.
I am fairly certain that the problem arises because clicking on a partially obscured row causes the grid to scroll to get that row fully visible, and this confuses the X and Y values passed to HitTest.
So my question is, how do I determine the row in this situation?
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
I am using th following code to determine the row clicked in a DataGrid:
Code:
Private Sub DgMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg.MouseUp
Dim hit As System.Windows.Forms.DataGrid.HitTestInfo
hit = sender.HitTest(e.X, e.Y)
If hit.Type = Windows.Forms.DataGrid.HitTestType.Cell Or hit.Column = -1 Then
sender.select(hit.Row)
End If
End Sub
The problem comes when there are more rows than can be displayed in the visible portion of the grid. Say there are 5 rows, but only 3 of them are fully visible, the fourth is half-visible (half of the row is obscured) and the fifth row is not visible at all without scrolling. If I click on rows 1-3, there is no problem. But if I click on row 4 while it is still partially obscured by the botom of the grid, then "hit.Row" returns -1 and the code "sender.select(hit.Row)" throws an "Index was outside the bounds of the array" error. If I scroll such that the 4th row is fully visible then everything is ok.
I am fairly certain that the problem arises because clicking on a partially obscured row causes the grid to scroll to get that row fully visible, and this confuses the X and Y values passed to HitTest.
So my question is, how do I determine the row in this situation?
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson