473,473 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling Public Event

I'm converting C# code to VB.Net and I completed everything but a couple
lines. I'm receiving an error Calling Public Event directly. Here is the
relevant code:

Public Class DataGridButtonColumns
Inherits DataGridTextBoxColumn

Public Event CellButtonClicked As DataGridCellButtonClickEventHandler

Private _button As Bitmap
Private _buttonPressed As Bitmap
Private _columnNum As Integer
Private _pressedRow As Integer

Public Sub HandleMouseUp(ByVal sender As Object, ByVal e As
MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean

If (hti.Column = Me._columnNum) And (hti.Row > -1) Then
isClickInCell = True
Else
isClickInCell = False
End If

_pressedRow = -1

Dim rect As Rectangle = New Rectangle(0, 0, 0, 0)

If isClickInCell = True Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = (e.X > rect.Right - Me._button.Width)
End If

If isClickInCell = True Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
DrawButton(g, Me._button, rect, hti.Row)
g.Dispose()

'Working C# Code
'if(CellButtonClicked != null)
' CellButtonClicked(this, new
DataGridCellButtonClickEventArgs(hti.Row, hti.Column));

'Code causing error:
If Not CellButtonClicked Is Nothing Then
CellButtonClicked(Me, New
DataGridCellButtonClickEventArgs(hti.Row, hti.Column))
End If
End If
End Sub

Thanks.

Josh.
Nov 21 '05 #1
1 1160
July 24, 2005

In VB.Net you cannot call events like methods. You must use the
RaiseEvent prefix when making events occur... for example:

RaiseEvent CellButtonClicked(Me, New
DataGridCellButtonClickEventArgs(hti.Row, hti.Column)) ' Uses the
RaiseEvent prefix when raising an event

This should work now... let me know if it doesn't. Thanks and I hope this
helps!
--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"jmhmaine" <jm*@online.nospam> wrote in message
news:99**********************************@microsof t.com...
I'm converting C# code to VB.Net and I completed everything but a couple
lines. I'm receiving an error Calling Public Event directly. Here is the
relevant code:

Public Class DataGridButtonColumns
Inherits DataGridTextBoxColumn

Public Event CellButtonClicked As DataGridCellButtonClickEventHandler

Private _button As Bitmap
Private _buttonPressed As Bitmap
Private _columnNum As Integer
Private _pressedRow As Integer

Public Sub HandleMouseUp(ByVal sender As Object, ByVal e As
MouseEventArgs)
Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
Dim hti As DataGrid.HitTestInfo = dg.HitTest(New Point(e.X, e.Y))
Dim isClickInCell As Boolean

If (hti.Column = Me._columnNum) And (hti.Row > -1) Then
isClickInCell = True
Else
isClickInCell = False
End If

_pressedRow = -1

Dim rect As Rectangle = New Rectangle(0, 0, 0, 0)

If isClickInCell = True Then
rect = dg.GetCellBounds(hti.Row, hti.Column)
isClickInCell = (e.X > rect.Right - Me._button.Width)
End If

If isClickInCell = True Then
Dim g As Graphics = Graphics.FromHwnd(dg.Handle)
DrawButton(g, Me._button, rect, hti.Row)
g.Dispose()

'Working C# Code
'if(CellButtonClicked != null)
' CellButtonClicked(this, new
DataGridCellButtonClickEventArgs(hti.Row, hti.Column));

'Code causing error:
If Not CellButtonClicked Is Nothing Then
CellButtonClicked(Me, New
DataGridCellButtonClickEventArgs(hti.Row, hti.Column))
End If
End If
End Sub

Thanks.

Josh.

Nov 21 '05 #2

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

Similar topics

6
by: Christian H | last post by:
Hi! I've created a custom control (myDrawControl) that deals with drawing. This control is then added to a form( myMainForm) Now, whenever something is dragged and dropped onto myDrawControl ,...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: NWx | last post by:
Hi, I defined a base class, Panel, based on System.Web.UI.UserControl, as below: Public MustInherit Class Panel Inherits System.Web.UI.UserControl ..... In another module, I want to...
7
by: John | last post by:
Hi I am opening word from my vb.net app. Is there a way to call a procedure in the vb.net app from a word macro? Thanks Regards
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
3
by: Jason | last post by:
I have an ASP.NET application in which I would like to call my button click event (imgSubmitSearch_Click) on the page load if certain criteria are met. Is this possible? What is the correct...
4
by: amaca | last post by:
In this slightly contrived (though small, complete and perfectly formed) example: public class Inner { public event EventHandler InnerHandler; public void DoSomething() { if ( InnerHandler...
3
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. ...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.