Home All Groups Group Topic Archive Search About

Confusion on Protected Overrides

Author
16 Mar 2006 4:06 PM
Ron Dahl
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

Author
16 Mar 2006 9:27 PM
Chris
Ron Dahl wrote:
Show quoteHide quote
> 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
>
>
>

You need to define the datagrid in the Form using the WithEvents keyword.

If that doesn't fix it, please show us your form1 code.

Chris
Author
22 Mar 2006 10:24 AM
Phill W.
"Ron Dahl" <rd***@ghp.com> wrote in message
news:ueGGPPRSGHA.4384@tk2msftngp13.phx.gbl...
> I'm very confused on how the Protected Overrides works.

Does your the program actually get into your overriding routine?
Put a break point in the code where you do the HitTest() call.

If /not/, then the Form /isn't/ using your new grid class.
Check the Designer-Generated code and make sure the grid on the
form is actually defined as /your/ grid class and not just a DataGrid.

HTH,
    Phill  W.