Adding Menu Item Access Keys Programmatically...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. My app uses user-based menu generation where all of the menu items are loaded from a SQLServer 2k database when the user logs in to the app. All is well except I cannot get an Access Key to load programmatically. That is, one of my entries in the database is &File, so when the menu item loads it should display in the Main Menu with the "F" underlined, but it doesn't. If I edit the Main Menu via it's interface, it works... but that goes against the data driven model. Any advice would be appreciated

Regards

Kevin
 
* "=?Utf-8?B?S2V2aW4=?= said:
Hello. My app uses user-based menu generation where all of the menu
items are loaded from a SQLServer 2k database when the user logs in to
the app. All is well except I cannot get an Access Key to load
programmatically. That is, one of my entries in the database is &File,
so when the menu item loads it should display in the Main Menu with the
"F" underlined, but it doesn't. If I edit the Main Menu via it's
interface, it works... but that goes against the data driven model. Any
advice would be appreciated.

Should work. Do the menmonics show up after pressing the Alt key?

<http://groups.google.de/[email protected]>
 
Yes they do, "Alt+F" will open the File Menu, but from reading MSDN, that is
the default behavior. That is, if there are no mnemonics assigned, then you
get "default" mnemonics assigned in top-down, left-to-right order. I'm
trying to explicitly assign a mnemonic that has the visual cue, but I cannot
get the "F" in File to be underlined.
 
* "Kevin said:
Yes they do, "Alt+F" will open the File Menu, but from reading MSDN, that is
the default behavior. That is, if there are no mnemonics assigned, then you
get "default" mnemonics assigned in top-down, left-to-right order. I'm
trying to explicitly assign a mnemonic that has the visual cue, but I cannot
get the "F" in File to be underlined.

"Post your code!"
 
Herfried,

After the user has been authenticated, EnableMenus runs. It calls a
recursive method

Private Sub EnableMenus(ByVal authenticated As Boolean)
menuMain.MenuItems.Clear()

If authenticated Then
'menuList is a list object based on Rockford Lahotka's CSLA.NET
(www.lhotka.net)
'it returns a list based on a table... this is the basis for my menu
list...
'Table is as follows:
'Col1: ID (int, pk)
'Col2: Text (varchar) Text of menu item
'Col3: ParentID (int) - self referential field... if = 0 then
top-level menu item (File, Edit, View, etc)
' if not = 0 then it is a "child" item of ID (so you can have
File|Open, etc)

'For simplicity, just think of menulist as a datatable and
liamMenuItem as a dataRow...
Dim menuList As LiamMenuItemList =
LiamMenuItemList.GetLiamMenuItemList()
Dim liamMenuItem As New LiamMenuItemList.LiamMenuItem

For Each liamMenuItem In menuList
Dim mi As MenuItem
mi = New MenuItem
If liamMenuItem.ParentId = 0 Then
'IF IAMMENUITEM.TEXT = &File THEN MI.TEXT SHOULD SHOW
THE VISUAL MNEMONIC
'THIS IS WHERE I AM STUCK

mi.Text = liamMenuItem.Text()

If mi.Text = "Window" Then
mi.MdiList = True
End If

If mi.Text = "Open Windows List" Then
mi.Checked = True
End If

'Load Child Menus allows n-level sub menus... called
recursively
LoadChildMenus(menuList, liamMenuItem.id, mi)

menuMain.MenuItems.Add(mi)
End If
Next

Else
'If not authenticated, just show the ability to attempt to login
again... not shown here for clarity and brevity
End If
End Sub

Private Sub LoadChildMenus(ByVal list As LiamMenuItemList, ByVal parentId As
Integer, _
ByVal owner As MenuItem)
Dim liamMenuItem As LiamMenuItemList.LiamMenuItem
For Each liamMenuItem In list
Dim mi As New MenuItem

If liamMenuItem.ParentId = parentId Then
mi.Text = liamMenuItem.Text
LoadChildMenus(list, liamMenuItem.id, mi)
AddHandler mi.Click, New System.EventHandler(AddressOf
menuMain_Click)
owner.MenuItems.Add(mi)
End If
Next
End Sub
 
Back
Top