Setting ShortCut property for MenuItems

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

Guest

I have a table (about 50 rows that populate the variables shown below in
lines 1 and 2) of shortcuts that I would like to read into a Windows Form.
The following code would work with one big exception:

CType will not convert a string to a MenuItem. (Line 3)

Dim MyShortCut As Integer = 13122 '13122 is integer for Ctrl2
Dim MyMenuItem As String = "MenuItem12"
Dim oMnu As Windows.Forms.MenuItem = CType(MyMenuItem,
Windows.Forms.MenuItem)
Dim oSC As Windows.Forms.Shortcut = CType(MyShortCut,
Windows.Forms.Shortcut)
oMnu.Shortcut = oSC

Is there a way to read and dynamically set this property from a table using
a different approach?
 
genojoe said:
I have a table (about 50 rows that populate the variables shown below in
lines 1 and 2) of shortcuts that I would like to read into a Windows Form.
The following code would work with one big exception:

CType will not convert a string to a MenuItem. (Line 3)

Dim MyShortCut As Integer = 13122 '13122 is integer for Ctrl2
Dim MyMenuItem As String = "MenuItem12"
Dim oMnu As Windows.Forms.MenuItem = CType(MyMenuItem,
Windows.Forms.MenuItem)
Try this:

Dim oMnu as New Windows.Forms.MenuItem(MyMenuItem, MyEventHandler,
MyShortcut)

or, set the shortcut after just setting the text.

Tom
 

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

Back
Top