Page 1 of 1

Search dialog to handle cancel or clear value

PostPosted: Tue Oct 18, 2022 1:30 pm
by perry
Hi All,

Just wondering if anyone has idea on how to best handle the Search Dialog when a custom field requires Select, Cancel or Clear (current value) actions.

I currently have, if cancelled, a message box to ask user if he wants to cancel or remove existing value.

Re: Search dialog to handle cancel or clear value

PostPosted: Tue Oct 18, 2022 3:34 pm
by SBarnes
Although I have not done this, you may find the following worth a look on how to add a context menu to the grid https://www.grapecity.com/spreadnet/doc ... tmenu.html

Re: Search dialog to handle cancel or clear value

PostPosted: Tue Oct 18, 2022 4:47 pm
by Scott.Pearce
Have a look at the Service Manager form, Main tab, "Prepaid Labour Pack" lookup. Right-click on it and you will see you get a "Clear" menu item in a context menu - this is how we tend to handle such a requirement. Here is the code:

In the form Setup():

Code: Select all
Dim NewToolStripMenuItem As ToolStripMenuItem
Dim myPrepaidLabourPackContextMenuStrip As ContextMenuStrip = New ContextMenuStrip
NewToolStripMenuItem = New ToolStripMenuItem("Clear", Nothing, AddressOf ClearPrepaidLabourPack, "Clear")
myPrepaidLabourPackContextMenuStrip.Items.Add(NewToolStripMenuItem)
PrepaidLabourPackLookup.ContextMenuStrip = myPrepaidLabourPackContextMenuStrip


The handler:

Code: Select all
Private Sub ClearPrepaidLabourPack(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If _Job.SelectedTaskNo >= 1 AndAlso _Job.SelectedTaskNo <= _Job.Tasks.Count Then
        Job.Tasks(Job.SelectedTaskNo).PrepaidLabourPack.Clear()
    End If
End Sub


Hope this helps. Let me know if you need more detail.

Re: Search dialog to handle cancel or clear value  Topic is solved

PostPosted: Tue Oct 18, 2022 5:01 pm
by Scott.Pearce
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.

Re: Search dialog to handle cancel or clear value

PostPosted: Thu Oct 20, 2022 4:53 pm
by perry
thank you both

Re: Search dialog to handle cancel or clear value

PostPosted: Wed Nov 02, 2022 5:25 pm
by Mike.Sheen
Coincidentally, I just had to do this for a customisation - so here's a plugin which demonstrates adding a context menu to custom field to clear the custom field contents for a lookup. It's for a line custom field, but the logic is interchangeable with plain custom fields.

The plugin adds a warehouse lookup custom field to the logical warehouses grid of the warehouse maintenance form - when the user clicks the lookup, a warehouse search is shown, and the user can select a warehouse. If the user wants to reset the value, right clicking on the custom field cell will show a context menu with a single option - "Clear" which does exactly what it implies - it clears the custom field contents to blank.

ClearContextMenu-WarehouseMaintenance.png

Re: Search dialog to handle cancel or clear value

PostPosted: Wed Nov 02, 2022 5:30 pm
by SBarnes
Given this is a common theme on the Jiwa Grid and the Jiwa lookup control could there be a way to bake this in as a property(clearable) and an event if the popup was called?

Re: Search dialog to handle cancel or clear value

PostPosted: Wed Nov 02, 2022 5:37 pm
by Mike.Sheen
SBarnes wrote:Given this is a common theme on the Jiwa Grid and the Jiwa lookup control could there be a way to bake this in as a property(clearable) and an event if the popup was called?


Good idea - but we'd need to recognise that people will sometimes want to have other context menu items, or be able to intercept the clear action of whatever we bake in - so we'd need to make sure it's customisable and overridable easily.

Logged as DEV-9640.

Shall I assign it to you, Stuart? :P

Re: Search dialog to handle cancel or clear value

PostPosted: Wed Nov 02, 2022 5:39 pm
by SBarnes
Sure I'll get to it after the current project is finalised and I've run out of things to do :lol: :lol: