Click-Event for runtime-built Toolbar Button Dropdown Menu 
Author Message
 Click-Event for runtime-built Toolbar Button Dropdown Menu

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 &
"\" & 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



Sat, 11 Dec 2004 14:50:36 GMT  
 Click-Event for runtime-built Toolbar Button Dropdown Menu
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.



Quote:
> 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
&
> "\" & 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




Sat, 11 Dec 2004 20:10:40 GMT  
 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

- Show quoted text -

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




Sat, 11 Dec 2004 21:30:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Dropdown button in a toolbar / Treeview right click

2. How to insert images in the dropdown toolbar button menu items in VB.

3. Simulating toolbar button click through menu item?

4. Toolbar button click causes validate event

5. Toolbar button click causes validate event.

6. Toolbar Button click event occurs twice!

7. toolbar button click event

8. Calling Menu Click Events at RunTime

9. Calling Menu Click Events at RunTime

10. How to make a toolbar button click down/click up

11. how to simulate click on dropdown menu?

12. toolbar, dropdown menu????

 

 
Powered by phpBB® Forum Software