Sorry, I just realised that you are referring to a grid lookup.
Have a look at the bank rec form (Jiwa->Cash Book->Bank Reconciliation). New demo data, create a new bank rec for Cash At Bank NSW, as of whatever the current date is. Right click in the Status column and see that you get a context menu. Code:
Properties:
- Code: Select all
Public WithEvents TransactionsContextMenuStrip As System.Windows.Forms.ContextMenuStrip
Public WithEvents UnreconcileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Public WithEvents ReconcileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Public WithEvents ClearToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Setup:
- Code: Select all
Private Sub SetupObjects()
TransactionsContextMenuStrip = New System.Windows.Forms.ContextMenuStrip()
UnreconcileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
ReconcileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
ClearToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
AddHandler TransactionsContextMenuStrip.Opening, AddressOf TransactionsContextMenuStrip_Opening
End Sub
Grid Setup:
- Code: Select all
Private Sub SetupTransactionsGrid()
TransactionsContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.UnreconcileToolStripMenuItem, Me.ReconcileToolStripMenuItem, Me.ClearToolStripMenuItem})
TransactionsContextMenuStrip.Name = "TransactionsContextMenuStrip"
TransactionsContextMenuStrip.Size = New System.Drawing.Size(186, 92)
UnreconcileToolStripMenuItem.Name = "UnreconcileToolStripMenuItem"
UnreconcileToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
UnreconcileToolStripMenuItem.Text = "Unreconcile"
ReconcileToolStripMenuItem.Name = "ReconcileToolStripMenuItem"
ReconcileToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
ReconcileToolStripMenuItem.Text = "Reconcile"
ClearToolStripMenuItem.Name = "ClearToolStripMenuItem"
ClearToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
ClearToolStripMenuItem.Text = "Clear"
End Sub
Control event handler:
- Code: Select all
Private Sub grdTransactions_CellClick(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs)
If e.Button = Windows.Forms.MouseButtons.Right Then
If e.ColumnHeader = False AndAlso e.Column = grdTransactions.ActiveSheet.Columns("Status").Index Then
TransactionsContextMenuStrip.Show(Cursor.Position)
End If
End If
End Sub
Transaction grid context menu handlers:
- Code: Select all
#Region "Transactions grid context menu handlers"
Private Sub TransactionsContextMenuStrip_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs)
If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated And EditPermission = JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
ClearToolStripMenuItem.Enabled = True
UnreconcileToolStripMenuItem.Enabled = True
ReconcileToolStripMenuItem.Enabled = True
Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
If Not selectedCells Is Nothing Then
For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "Opening Balance Transaction" Then
ClearToolStripMenuItem.Enabled = False
ElseIf TransactionType.Trim = "Direct GL Transaction" Or TransactionType.Trim = "Direct Debtor Receipt" Or TransactionType.Trim = "Direct Debtor Payment" Or TransactionType.Trim = "Direct Creditor Receipt" Or TransactionType.Trim = "Direct Creditor Payment" Then
ClearToolStripMenuItem.Enabled = False
UnreconcileToolStripMenuItem.Enabled = False
End If
End If
Next
Next
Else
e.Cancel = True
End If
Else
e.Cancel = True
End If
End Sub
Private Sub UnreconcileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim oldCursor As Cursor = Cursor
Try
Cursor = Cursors.WaitCursor
If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
If Not selectedCells Is Nothing Then
For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
If selectedCells(currentSelectionBlock).Row = -1 Then
'All rows
For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Unreconciled
ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Unreconciled
End If
End If
Next
Else
For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Unreconciled
ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Unreconciled
End If
End If
Next
End If
Next
End If
End If
Finally
Cursor = oldCursor
End Try
End Sub
Private Sub ReconcileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim oldCursor As Cursor = Cursor
Try
Cursor = Cursors.WaitCursor
If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
If Not selectedCells Is Nothing Then
For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
If selectedCells(currentSelectionBlock).Row = -1 Then
'All rows
For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Reconciled
ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Reconciled
End If
End If
Next
Else
For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Reconciled
ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Reconciled
End If
End If
Next
End If
Next
End If
End If
Finally
Cursor = oldCursor
End Try
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim oldCursor As Cursor = Cursor
Try
Cursor = Cursors.WaitCursor
If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
If Not selectedCells Is Nothing Then
For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
If selectedCells(currentSelectionBlock).Row = -1 Then
'All rows
For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Cleared
End If
End If
Next
Else
For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
If Not TransactionType Is Nothing Then
If TransactionType.Trim = "GL Transaction" Then
BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Cleared
End If
End If
Next
End If
Next
End If
End If
Finally
Cursor = oldCursor
End Try
End Sub
#End Region
As you can see from this post and my previous one, there are a few different ways that context menus can be done. Further, Infragistics (a control suite which we use and is shipped with Jiwa) offer a control agnostic context menu which can also be used, and it has many more features like icons, etc.