Help with Event handler, withevents, raise events

  • Thread starter Thread starter Ty
  • Start date Start date
T

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
 
Ty said:
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
 
Ty said:
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
 
                              ^

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
 
                              ^

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
 
Ty said:
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
 
Ty said:
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
 
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
 
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
 
Ty said:
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
 
Ty said:
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
 
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
 
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
 
Back
Top