|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help with Event handler, withevents, raise eventshandles 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 You have the Handles clause commented out! see the '
-- Show quoteHide quoteTerry "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 > 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 On May 25, 5:03 pm, "Armin Zingler" <az.nos***@freenet.de> wrote: Sorry The ' was just as I was try a different approach. Ignore it and> 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 assume that line is not commented out. Ty Ty wrote:
Show quoteHide quote > On May 25, 5:03 pm, "Armin Zingler" <az.nos***@freenet.de> wrote: Is variable dtEvent designer generated? If not, do you also assign the >> 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. Treeview to variable dtEvent or do you only add it to the Form? Armin
Show quote
Hide quote
On May 25, 7:22 pm, "Armin Zingler" <az.nos***@freenet.de> wrote: The treeview is added dynamically in the form load event below> 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 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 wrote:
Show quoteHide quote >> I see two variables (and Treeviews): DirTree and dtEvent. You don't add >> 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 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
save treeview state and call from another form
use variable as textbox name? treeview in windowsdialog Call button click event is it save to call functions from another form? Bracketed types Using function with PChar data type Build Number - how to auto increment? Bitmap from a file windows.forms.controls |
|||||||||||||||||||||||