Home All Groups Group Topic Archive Search About

Help with Event handler, withevents, raise events

Author
25 May 2009 8:51 PM
Ty
I have a class that I have created that inherits the Treeview. It
handles and raises an event. The event fires but the sub for the form
never sees the event.

Here is my code.

CLASS

Imports System.IO

Public Class DirectoryTreeview
    Inherits TreeView
    Public Event DirectorySelected(ByVal sender As Object, ByVal e As
DirectorySelectedEventArgs)
    Private _Drive As Char

    Protected Overrides Sub OnAfterSelect(ByVal e As
TreeViewEventArgs)
        MyBase.OnAfterSelect(e)
        RaiseEvent DirectorySelected(Me, New DirectorySelectedEventArgs
(e.Node.FullPath))
    End Sub
End Class

Public Class DirectorySelectedEventArgs
    Inherits EventArgs
    Public DirectoryName As String
    Public Sub New(ByVal DirectoryName As String)
        Me.DirectoryName = DirectoryName
    End Sub


End Class

VB FORM CODE
Public WithEvents dtEvent As DirectoryTreeview

SUB TO HANDEL EVENT
    Private Sub GetFiles(ByVal sender As Object, ByVal e As
DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected

      Msgbox("Event Fired")

    End Sub

Any help with why this is not working would be appreciated.

Ty

Author
25 May 2009 9:03 PM
Terry
You have the Handles clause commented out!  see the '
--
Terry


Show quoteHide quote
"Ty" wrote:

> I have a class that I have created that inherits the Treeview. It
> handles and raises an event. The event fires but the sub for the form
> never sees the event.
>
> Here is my code.
>
> CLASS
>
> Imports System.IO
>
> Public Class DirectoryTreeview
>     Inherits TreeView
>     Public Event DirectorySelected(ByVal sender As Object, ByVal e As
> DirectorySelectedEventArgs)
>     Private _Drive As Char
>
>     Protected Overrides Sub OnAfterSelect(ByVal e As
> TreeViewEventArgs)
>         MyBase.OnAfterSelect(e)
>         RaiseEvent DirectorySelected(Me, New DirectorySelectedEventArgs
> (e.Node.FullPath))
>     End Sub
> End Class
>
> Public Class DirectorySelectedEventArgs
>     Inherits EventArgs
>     Public DirectoryName As String
>     Public Sub New(ByVal DirectoryName As String)
>         Me.DirectoryName = DirectoryName
>     End Sub
>
>
> End Class
>
> VB FORM CODE
> Public WithEvents dtEvent As DirectoryTreeview
>
> SUB TO HANDEL EVENT
>     Private Sub GetFiles(ByVal sender As Object, ByVal e As
> DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected
>                                             ^  remove the '
>       Msgbox("Event Fired")
>
>     End Sub
>
> Any help with why this is not working would be appreciated.
>
> Ty
>
Author
25 May 2009 9:03 PM
Armin Zingler
Ty wrote:
>    Private Sub GetFiles(ByVal sender As Object, ByVal e As
> DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected

                              ^

Does this apostrophe have any special meaning? (other than causing the
problem...)


Armin
Author
25 May 2009 10:59 PM
Ty
On May 25, 5:03 pm, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Ty wrote:
> >    Private Sub GetFiles(ByVal sender As Object, ByVal e As
> > DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected
>
>                               ^
>
> Does this apostrophe have any special meaning? (other than causing the
> problem...)
>
> Armin

Sorry The ' was just as I was try a different approach. Ignore it and
assume that line is not commented out.

Ty
Author
25 May 2009 11:22 PM
Armin Zingler
Ty wrote:
Show quoteHide quote
> On May 25, 5:03 pm, "Armin Zingler" <az.nos***@freenet.de> wrote:
>> Ty wrote:
>>> Private Sub GetFiles(ByVal sender As Object, ByVal e As
>>> DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected
>>
>> ^
>>
>> Does this apostrophe have any special meaning? (other than causing
>> the problem...)
>>
>> Armin
>
> Sorry The ' was just as I was try a different approach. Ignore it and
> assume that line is not commented out.


Is variable dtEvent designer generated? If not, do you also assign the
Treeview to variable dtEvent or do you only add it to the Form?


Armin
Author
25 May 2009 11:43 PM
Ty
Show quote Hide quote
On May 25, 7:22 pm, "Armin Zingler" <az.nos***@freenet.de> wrote:
> Ty wrote:
> > On May 25, 5:03 pm, "Armin Zingler" <az.nos***@freenet.de> wrote:
> >> Ty wrote:
> >>> Private Sub GetFiles(ByVal sender As Object, ByVal e As
> >>> DirectorySelectedEventArgs) 'Handles dtEvent.DirectorySelected
>
> >> ^
>
> >> Does this apostrophe have any special meaning? (other than causing
> >> the problem...)
>
> >> Armin
>
> > Sorry The ' was just as I was try a different approach. Ignore it and
> > assume that line is not commented out.
>
> Is variable dtEvent designer generated? If not, do you also assign the
> Treeview to variable dtEvent or do you only add it to the Form?
>
> Armin

The treeview is added dynamically in  the form load event below

Dim DirTree As New DirectoryTreeview
        dtEvent = New DirectoryTreeview

        DirTree.Size = New Size(SplitContainer1.Panel1.Width,
SplitContainer1.Panel1.Height)
        DirTree.Location = New Point(5, 5)
        DirTree.Drive = "C"
        SplitContainer1.Panel1.Controls.Add(DirTree)

Thanks,
Ty
Author
25 May 2009 11:56 PM
Armin Zingler
Ty wrote:
Show quoteHide quote
>>
>> Is variable dtEvent designer generated? If not, do you also assign
>> the Treeview to variable dtEvent or do you only add it to the Form?
>>
>> Armin
>
> The treeview is added dynamically in  the form load event below
>
> Dim DirTree As New DirectoryTreeview
>         dtEvent = New DirectoryTreeview
>
>         DirTree.Size = New Size(SplitContainer1.Panel1.Width,
> SplitContainer1.Panel1.Height)
>         DirTree.Location = New Point(5, 5)
>         DirTree.Drive = "C"
>         SplitContainer1.Panel1.Controls.Add(DirTree)
>
> Thanks,
> Ty

I see two variables (and Treeviews): DirTree and dtEvent. You don't add
dtEvent to the
panel, only DirTree.


Armin
Author
26 May 2009 9:30 AM
Ty
Thanks Armin,

I did so many changes that I did not realize that I was never actually
creating the Treeview. I changed the DirTree lines to dtEvent and it
works.

Ty