|
-
Oct 9th, 2009, 09:13 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Event Handler Error
I get this error on my form, not sure what to do:
Error 1 Option Strict On does not allow narrowing in implicit type conversions between method 'Private Sub searchResult_SearchFileMatches(sender As Object, e As Jam.Shell.FileMatchEventArgs)' and delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'.
on RED Text
Code:
Private ReadOnly Property FileMatchEventHandler() As EventHandler
Get
If (FileMatchEventHandler Is Nothing) Then
FileMatchEventHandler = AddressOf searchResult_SearchFileMatches
End If
Return FileMatchEventHandler
End Get
End Property
-
Oct 9th, 2009, 09:21 AM
#2
Re: Event Handler Error
Use the generic EventHandler type
Code:
Private ReadOnly Property FileMatchEventHandler() As EventHandler(Of Jam.Shell.FileMatchEventArgs)
Get
If (FileMatchEventHandler Is Nothing) Then
FileMatchEventHandler = AddressOf searchResult_SearchFileMatches
End If
Return FileMatchEventHandler
End Get
End Property
-
Oct 9th, 2009, 09:56 AM
#3
Thread Starter
Addicted Member
Re: Event Handler Error
I have another error:-
Not sure what to do?
Error 1 'Public Event SearchFileMatches(sender As Object, e As Jam.Shell.FileMatchEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Error 1
Code:
Private Sub searchResults_SearchCompleted(ByVal sender As System.Object, ByVal e As Jam.Shell.SearchCompletedEventArgs) Handles searchResults.SearchCompleted
'remove the filematching eventhandler if specified, see buttStartSearch_Click
searchResults.SearchFileMatches -= FileMatchEventHandler
buttStopSearch.Enabled = False
buttStartSearch.Enabled = True
'reset the progress indicator
SearchProgressBar.Visible = False
SearchProgressBar.Value = 0
'allow sorting again
searchResults.HeaderStyle = ColumnHeaderStyle.Clickable
'the search was cancelled by the user
If e.Cancelled Then
toolStripStatusLabel1.Text = "The search operation was cancelled by the user."
Exit Sub
End If
'an error/exception occurred during the search, inform the user
If e.[Error] IsNot Nothing Then
Dim errString As String = "An Error occurred: " & e.[Error].Message
MessageBox.Show(errString, "Search error", MessageBoxButtons.OK, MessageBoxIcon.Information)
toolStripStatusLabel1.Text = errString
Else
'all went ok, the search is complete
toolStripStatusLabel1.Text = "The search operation completed."
End If
End Sub
-
Oct 9th, 2009, 09:59 AM
#4
Re: Event Handler Error
VB does not support C# style +=/-= syntax for event wireup. You should use AddHandler and RemoveHandler to add and remove event handlers.
-
Oct 9th, 2009, 10:03 AM
#5
Re: Event Handler Error
Are you switching to VB from C# by any chance? It looks like you're trying to use C# syntax in VB. You use AddHandler and RemoveHandler to add and remove event handlers in VB, e.g.
vb.net Code:
RemoveHandler searchResults.SearchFileMatches, AddressOf FileMatchEventHandler
Of course, the event handler would have to have been added using AddHandler in the first place.
-
Oct 9th, 2009, 10:08 AM
#6
Thread Starter
Addicted Member
Re: Event Handler Error
Yes, I converted the code from c#.
I have this code at the start:-
Code:
Private m_fileMatchEventHandler As EventHandler(Of FileMatchEventArgs)
''' <summary>
''' provide on-access to our selfdefined file matching handler that extends the
''' search filter.
''' </summary>
Private ReadOnly Property FileMatchEventHandler() As EventHandler(Of FileMatchEventArgs)
Get
If m_fileMatchEventHandler Is Nothing Then
m_fileMatchEventHandler = New EventHandler(Of FileMatchEventArgs)(AddressOf searchResults_SearchFileMatches)
End If
Return m_fileMatchEventHandler
End Get
End Property
-
Oct 9th, 2009, 10:15 AM
#7
Re: Event Handler Error
I don't understand why you have a property returning an event handler. What is the purpose of that?
-
Oct 9th, 2009, 10:15 AM
#8
Thread Starter
Addicted Member
Re: Event Handler Error
Thanks for your help, managed to get it working with:
Code:
RemoveHandler searchResults.SearchFileMatches, FileMatchEventHandler
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|