By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

How to call an Event ?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
I forgot to say I use a class inherit from datagrid, so I can not call
RaiseEvent.

Stan
Nov 20 '05 #2

P: n/a
* "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

P: n/a
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

P: n/a
"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

P: n/a
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.