I'm very confused on how the Protected Overrides works.
I created a new project with a new form1 and a new datagrid called
myDataGrid.
I created a simple DataTable and put 5 rows and 5 columns of data into it.
I bound the DataTable to the DataGrid.
The example at the end of this post is exactly as copied from the vb.net
help screen:
I put the new myDataGrid Class following the Form1 Class.
I can make the code work with a Button Click event, but not the MouseDown
event.
When I click on a row it is not selected.
I don't understand how to connect the MouseDown mouse event to my form1
class to make the connection.
How do I properly create an instance of the myDataDrid class?
Do I need eventhandler code of some sort in Form1?
Do I need a delegate or something to make this example work?
Thanks in advance for any help or pointing me in the right direction.
Ron Dahl
Public Class MyDataGrid
Inherits DataGrid
' Override the OnMouseDown event to select the whole row
' when the user clicks anywhere on a row.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
' Get the HitTestInfo to return the row and pass
' that value to the IsSelected property of the DataGrid.
Dim hit As DataGrid.HitTestInfo = Me.HitTest(e.X, e.Y)
If hit.Row < 0 Then
Return
End If
If IsSelected(hit.Row) Then
UnSelect(hit.Row)
Else
[Select](hit.Row)
End If
End Sub
End Class