Help with Event handler, withevents, raise events


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
 
Ad

Advertisements

A

Armin Zingler

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
 
A

Armin Zingler

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
 
T

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
 
Ad

Advertisements

T

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
 
A

Armin Zingler

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
 
A

Armin Zingler

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
 
T

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
 
T

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
 
Ad

Advertisements

A

Armin Zingler

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
 
A

Armin Zingler

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
 
T

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
 
Ad

Advertisements

T

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Raise event problem 1
Raising an event from a user control 2
WithEvent 1
How to use WaitforSingleObject on events 13
Remove Event Handlers C# style 6
Raising Events 2
Threading & raising event question 4
Events 3

Top