Page 1 of 1

Renaming the "Duty"'field on a GRN

PostPosted: Wed Feb 17, 2016 5:47 pm
by Atronics
I need to rename the Duty field on the GRN form. Using the Permissions option to find the fieldname does not identify this field.

Re: Renaming the "Duty"'field on a GRN  Topic is solved

PostPosted: Thu Feb 18, 2016 8:07 am
by Scott.Pearce
It's a cell in a grid. Using the "Set Permissions" form, I can see that grid is called "CartageJiwaGrid". Using "Manage Grid", I can see that the column tag for the column in which the text "Duty" resides is "RowHeading". Using "Manage Grid", I also reveal the "Key" column, and find that the row for "Duty" has a key of "Duty". The key column allows identification of a given row even when the grid is sorted in some arbitrary way. In many of our grids the "key" of a row would be the RecID related to the record data being displayed.

To change the text of the Duty cell, one would start by hooking into an appropriate event - I chose form_shown because by this point all the controls have been set up:

Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim GRNFormObject As JiwaInvReceivalUI.MainForm = JiwaForm
      AddHandler GRNFormObject.Shown, AddressOf GRNFormObject_Shown
    End Sub


Don't forget to add a reference to the "Goods Received Note" form on the Forms tab of the plugin!

Then, the handler itself is thus:

Code: Select all
   Public Sub GRNFormObject_Shown(sender As Object, e As System.EventArgs)
      Dim GRNFormObject As JiwaInvReceivalUI.MainForm = sender
      
      With GRNFormObject.CartageJiwaGrid
         Dim rowKey As String = ""
         Dim dutyRowNo As Integer = -1
         
         'Find the Duty row
         For MyLoop As Integer = 0 To .ActiveSheet.RowCount - 1 'Grids are 0-based - the - 1 accounts for this.
            rowKey = .GridText("Key", MyLoop)
            If rowKey = "Duty" Then
               dutyRowNo = MyLoop
               Exit For 'We've found the row we are interested in.
            End If
         Next
         
         'Assuming we found the Duty row OK, we can now set the text of the "RowHeading" column for that row.
         .GridText("RowHeading", dutyRowNo) = "Import Levy"
      End With
   End Sub


In the handler code, we start by obtaining the form via the "sender" of the event - this allows us to reach the grid of interest. Then, we iterate through the grid looking for the "Duty" row. Finally, having found the row we want to modify, we use GridText to set the text of the cell at column "RowHeading", row "dutyRowNo".

I've attached the full plugin.

Re: Renaming the "Duty"'field on a GRN

PostPosted: Thu Feb 18, 2016 10:29 am
by Atronics
Thanks, Scott.