
Click-Event for runtime-built Toolbar Button Dropdown Menu
Hi Sven,
thank you for your tip. This works great! Another cool feature in VB.Net.
Regards,
Heinz R. Vahlbruch
Quote:
> Hi Heinz
> Have you used the AddHandler method? It takes as its parameters the event
to
> be caught and the function to execute when the event is fired.
> AddHandler mnuSubItem.Click, AddressOf mnuSubItem_Click
> Private Sub mnuSubItem_Click (byref sender as Object, byref e as
EventArgs)
> Of course, you can't have your menu clicks execute a new function, since I
> don't think it is possible to add procedures at run-time.
> Hope this helps
> --
> Regards
> Sven Aelterman
> IT
> Global Communication N.V.
message
> > Hello,
> > I have a dropdown button on my toolbar which uses a context menu. This
> > context menu is built at runtime by displaying a folder content with
> folders
> > and files as menu items. This all works fine, but I can't add manually
> event
> > handlers because I don't know what menu items will be there at runtime.
I
> > have a problem to find out what menu item is clicked at runtime. Any
help
> is
> > very much appreciated.
> > Here is my code snippet:
> > For nCounter = 0 To sSortDirs.Count - 1 'sorted list with directories
> > 'add main menu items for each folder
> > Dim mnuItem As New MenuItem()
> > mnuItem.Text = sSortDirs(nCounter)
> > Me.ctmDropDown.MenuItems.Add(mnuItem)
> > sSortFiles =
clsFileFunctions.GetFilesInFolder(mdlAppData.g_sPoolPath
Quote:
> &
> > "\" & sSortDirs(nCounter)) 'sorted list with files in directory
> > 'add file menu items only if there are files in folder
> > If sSortFiles.Count > 0 Then
> > For nInnerCounter = 0 To sSortFiles.Count - 1
> > Dim mnuSubItem As New MenuItem()
> > mnuSubItem.Text = sSortFiles(nInnerCounter)
> > mnuItem.MenuItems.Add(mnuSubItem)
> > Next
> > Else
> > 'disable menu item if there are no files in folder
> > mnuItem.Enabled = False
> > End If
> > Next
> > Thank you and have a great day!
> > Heinz R. Vahlbruch