I'd be grateful if anybody could shed some light on a problem. I have a form showing a sales order, this has a DGV (DGVDocs) showing a list of invoices against that order. I've populated a print button with the documents and for each a submenu with Print, Preview, PDF. The lambda expressions on the submenu always pick up the last entry on the menu.
Private Sub create_print_menu()
Dim i As Integer = 0
ms = New ContextMenuStrip
If dgvDocs.Rows.Count > 0 Then
Dim doctype As String = ""
Dim docno As Integer = 0
For i = 0 To dgvDocs.Rows.Count - 1
ms.Items.Add(RTrim(dgvDocs.Rows(i).Cells(0).Value) & " " & RTrim(dgvDocs.Rows(i).Cells(2).Value))
jc = ms.Items(ms.Items.Count - 1)
doctype = RTrim(dgvDocs.Rows(i).Cells(0).Value)
docno = RTrim(dgvDocs.Rows(i).Cells(2).Value)
jc.DropDownItems.Add("Preview", Nothing, Function(sender, e) docPreview(doctype, docno))
Next
End If
End Sub
Private Function docPreview(ByVal doctype As String, ByVal docno As Integer)
If doctype.ToUpper.Contains("DESPATCH NOTE") Then
Dim frm As New frmDespatchPreview
frm.delnote = docno
frm.ShowDialog()
ElseIf doctype.ToUpper.Contains("INVOICE") Then
Dim frm As New frmInvoicePreview
frm.invno = docno
frm.ShowDialog()
End If
Return True
Return True
End Function