471,066 Members | 1,233 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to call an Event ?

Hi,
How can I call an event from an action.
Example, I want to call the datagrid.Double.click event when a button is
pressed.

Stan.
Nov 20 '05 #1
5 1565
I forgot to say I use a class inherit from datagrid, so I can not call
RaiseEvent.

Stan
Nov 20 '05 #2
* "Stan Sainte-Rose" <st**@cyber972.com> scripsit:
How can I call an event from an action.
Example, I want to call the datagrid.Double.click event when a button is
pressed.


Why not put the code from the handler into a separate procedure and call
this procedure from the handler and the button's 'Click' event handler?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Herfried,

In fact, I use this bit of code and I want when I press the Enter key from a
datagrid to raise the DoubleClick
And as I have many datagrids I think it's not really cool to write a
procedure for each datagrid.
Public Class DataGridEnter
Inherits DataGrid
Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As
Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
------- Raise my Event..
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function 'ProcessCmdKey

End Class

Stan

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news:bu************@ID-208219.news.uni-berlin.de...
* "Stan Sainte-Rose" <st**@cyber972.com> scripsit:
How can I call an event from an action.
Example, I want to call the datagrid.Double.click event when a button is
pressed.


Why not put the code from the handler into a separate procedure and call
this procedure from the handler and the button's 'Click' event handler?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
"Stan Sainte-Rose" <st**@cyber972.com> schrieb
Hi,
How can I call an event from an action.
Example, I want to call the datagrid.Double.click event when a button
is pressed.


You can not call an event, but you can call the same procedure that you call
in the double-clicke event handler.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Stan,
If you are deriving from a control (or other class) you can raise a base
event, by calling a special a special protected method. For example the
DataGrid.DoubleClick event is raised by the DataGrid.OnDoubleClick method.
This DoubleClick/OnDoubleClick relationship is a standard design pattern in
..NET that I would recommend you follow in your own classes. For details see:

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...Guidelines.asp
You would need something like:

Public Class DataGridEnter
Inherits DataGrid

Protected Overrides Function ProcessCmdKey( _
ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) _
As Boolean
If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
MyBase.OnDoubleClick(EventArgs.Empty)
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function 'ProcessCmdKey

End Class

Note in VB.NET your OnMyEvent method can simply call RaiseEvent MyEvent, as
RaiseEvent will check to see if there are any handlers...

Hope this helps
Jay

"Stan Sainte-Rose" <st**@cyber972.com> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
Hi,
How can I call an event from an action.
Example, I want to call the datagrid.Double.click event when a button is
pressed.

Stan.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ricky W. Hunt | last post: by
4 posts views Thread by Paul | last post: by
3 posts views Thread by Ignacio Machin | last post: by
reply views Thread by leo001 | last post: by

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.