0

Facing an issue while accessing declared event in vb.net.

Please go thorough below example. (I have modified below stuff to make understable as it is part of one of custom control development)

Public Class Main
    Inherits ComboBox

    'Event handler for when an item check state changes.
    Public Event ItemCheck As ItemCheckEventHandler
    Private parentMainClass As Main
    Private cclb As controlClass

    Public Sub New(parentclass As Main)
        Me.parentMainClass = parentclass
        'Add a handler to notify our parent of ItemCheck events.
        AddHandler Me.cclb.ItemCheck, New System.Windows.Forms.ItemCheckEventHandler(AddressOf Me.cclb_ItemCheck)
    End Sub

    Private Sub cclb_ItemCheck(sender As Object, e As ItemCheckEventArgs)
        'If ccbParent.ItemCheck IsNot Nothing Then
            RaiseEvent parentMainClass.ItemCheck(sender,e)
        'End If
    End Sub

    Public Class controlClass
        Inherits CheckedListBox
    End Class
End Class

Problem: RaiseEvent parentMainClass.ItemCheck(sender,e) this statement shows - ItemCheck event not exists even though it is existed.

Please guide.

Thank You

David -
  • 2,009
  • 1
  • 13
  • 9
user3711357
  • 1,425
  • 7
  • 32
  • 54

2 Answers2

1

The event declaration;

Public Event ItemCheck As ItemCheckEventHandler

Should be;

Public Event ItemCheck(sender As Object, e As ItemCheckEventArgs)

What the error is telling you is that it cannot match up the event to the event handler signature.

Grim
  • 672
  • 4
  • 17
  • Getting error as `'parentMainClass' is not an event of Main` and `End of statement Expected`. when I do comment comment this RaiseEvent statement then both the errors are removed. – user3711357 Aug 11 '14 at 16:23
  • you can copy paste this class into any application and you will found same error. (as this is separate class). NOt understand this weired error ,looks like, `parentMainClass` is considred as an event instead of object.. – user3711357 Aug 11 '14 at 16:25
  • OK, my mistake, I should have tested it more thoroughly. This answer can be deleted when you find an accepted one! – Grim Aug 11 '14 at 16:29
  • np. I need http://www.codeproject.com/Articles/31105/A-ComboBox-with-a-CheckedListBox-as-a-Dropdown control in vb.net as I need to use this in vb.net but facing an issue while convereted to code and it is particularly for this ItemCheck event facing an issue. Any support will be appreciated. Thanks. – user3711357 Aug 11 '14 at 16:32
  • Why don't you just compile the C# version into a control and then just reference it from your VB project?!!? – Grim Aug 11 '14 at 16:34
0

From your original code, the line;

RaiseEvent parentMainClass.ItemCheck(sender, e)

should be changed to;

RaiseEvent ItemCheck(sender, e)

This raises the ItemCheck event from the current instance. What you seem to be wanting to do is to raise the event on the parent instance, which is a bit different.

Grim
  • 672
  • 4
  • 17