473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Confusion on Protected Overrides

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

Mar 16 '06 #1
2 9942
Ron Dahl wrote:
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
Mar 16 '06 #2

"Ron Dahl" <rd***@ghp.com> wrote in message
news:ue**************@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.
Mar 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mustaq | last post by:
Hi How to cancel Protected Overrides Sub OnStop() in windows services Regards, Mustaq
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
5
by: Greg McKnight | last post by:
This may be the second time this post is showing, I accidentally shut down my browser. Sorry if it is a repeat. I am a newbie to VB.net, so please forgive me if these are simple questions. ...
3
by: flat_ross | last post by:
For anyone who is just getting into VB.NET and/or is starting to work with inheritance I would like to point out a potential pitfall. We found this confusion recently when code-reviewing an...
4
by: Stephen Costanzo | last post by:
My goal is to have a property or function that returns different types of returns with no initial arguments. For example Public Class Something Private sData as string Private lData as long ...
4
by: dbuchanan | last post by:
Is the following behavior normal? Both the 'Protected sub' in the inherited form and the 'Private Shadows sub' in the derived form fires. My interpretation of MSDN help on the topic "Shadows"...
4
by: Rulin Hong | last post by:
According to OO, interface is just a bunch of definitions, no implementation at all. It's also true when we write our own code in .NET. But I find every interface provided by .NET has specific...
3
by: Gregory A Greenman | last post by:
I'm trying to screen scrape a site that requires a password. If I access the site's login page in my browser and view the source, I see that it does not contain a viewstate. When my program...
13
by: Clive Dixon | last post by:
I am refactoring some code to move some base classes into a separate assembly. One of these base classes has a member property which is 'protected internal'. However when I move these base classes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.