I have a ContextMenu attached to a tray notifyIcon and I already have it on the form in design mode. If I look at it in design mode I can see evereything that I have on the main pop-up context menu. What I am trying to do is add to one of those choices programatically. Worked fine in VB6.
I am reading in a list of filenames from a directory and want to place them as menu items in the 2nd level of the context menu.
Example:
Show Quote Window Main Context Menu Item
Always On Top Main Context Menu Item
--Seperator--
.
.
.
Choose RQG data file(s) Main Context Menu Item
Aristotle.txt dynamically loaded
Mark Twain.txt user can check or un-check
Will Rogers.txt each of these
Automatic change interval
.
.
.
Exit
Primary problem is what changed in VB.NET from VB6 that broke my program and what do I need to do to fix the dynamic build.
I will include the part where i am getting errors -
and the on-click handler
The error I am getting in Visual Studio is -
Thanks,
Ray
I am reading in a list of filenames from a directory and want to place them as menu items in the 2nd level of the context menu.
Example:
Show Quote Window Main Context Menu Item
Always On Top Main Context Menu Item
--Seperator--
.
.
.
Choose RQG data file(s) Main Context Menu Item
Aristotle.txt dynamically loaded
Mark Twain.txt user can check or un-check
Will Rogers.txt each of these
Automatic change interval
.
.
.
Exit
Primary problem is what changed in VB.NET from VB6 that broke my program and what do I need to do to fix the dynamic build.
I will include the part where i am getting errors -
VB.NET:
Public Sub BuildChooseFileMenuItems()
Dim k As Integer
Dim numChecked As Integer
Dim RandomSelectEnabled As Boolean = False
ReDim ChooseFileMenu(UBound(QuoteFiles) + 1)
numChecked = 0
For k = 0 To UBound(QuoteFiles)
ChooseFileMenu(k) = Me.mnuChooseRQGFiles.MenuItems.Add(QuoteFiles(k), AddressOf mnuChooseRQGFiles_Click)
ChooseFileMenu(k).Enabled = True
If QuoteFilesChecked(k) = "T" Then
ChooseFileMenu(k).Checked = True
numChecked = numChecked + 1
Else
ChooseFileMenu(k).Checked = False
End If
If RandomSelectEnabled = True Then
If ChooseFileMenu(k).Text <> "-" Then
ChooseFileMenu(k).Enabled = False
End If
End If
If ChooseFileMenu(k).Text = "Random Select" Then
If ChooseFileMenu(k).Checked = True Then
RandomSelectEnabled = True
End If
End If
Next
If numChecked < 1 Then
ChooseFileMenu(0).Checked = True
QuoteFilesChecked(0) = "T"
For k = 2 To UBound(QuoteFiles) - 1
ChooseFileMenu(k).Enabled = False
Next
End If
End Sub
and the on-click handler
VB.NET:
Private Sub mnuChooseRQGFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuChooseRQGFiles.Click
Dim miClicked As MenuItem = CType(sender, MenuItem)
Dim m As Integer
For m = 0 To UBound(QuoteFiles)
If QuoteFiles(m) = miClicked.Text Then
If miClicked.Checked = True Then
miClicked.Checked = False
QuoteFilesChecked(m) = "F"
Else
miClicked.Checked = True
QuoteFilesChecked(m) = "T"
End If
End If
Next
If miClicked.Text = "Random Select" Then
If miClicked.Checked = False Then
For m = 2 To UBound(QuoteFiles) - 1
ChooseFileMenu(m).Enabled = True
Next
Else
For m = 2 To UBound(QuoteFiles) - 1
ChooseFileMenu(m).Enabled = False
Next
End If
End If
Open_QuoteFile()
End Sub
The error I am getting in Visual Studio is -
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Exception detail -
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="RQG"
StackTrace:
at RQG.RQGForm.BuildChooseFileMenuItems() in C:\Documents and Settings\Ray\Desktop\RQG\frmQuotes.vb:line 671
at RQG.RQGForm.RQGForm_Load(Object eventSender, EventArgs eventArgs) in C:\Documents and Settings\Ray\Desktop\RQG\frmQuotes.vb:line 463
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at RQG.RQGMainModule.Main() in C:\Documents and Settings\Ray\Desktop\RQG\RQGMainModule.vb:line 61
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Thanks,
Ray