Calling Public Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
Back
Top