Page 1 of 1

Grid custom checkbox column

PostPosted: Wed Oct 28, 2015 11:40 am
by neil.interactit
I am adding some custom columns programmatically ... all working well. The following code:

Code: Select all
    Private Sub ShowLedgerNumberColumn(activeSheet As Sheet)
        Dim xmlString = activeSheet.GenerateXMLDefinition()
        Dim xmlDocument = New XmlDocument
        xmlDocument.LoadXml(xmlString)
        Dim listOfColumns As XmlElement = xmlDocument.SelectSingleNode("JiwaGridDefinition/ListOfColumns")
        If listOfColumns Is Nothing Then Return
        Dim updated = ShowColumnAs(listOfColumns, "UserDefinedString1", "Ledger Number")
        updated = updated Or ShowColumnAs(listOfColumns, "UserDefinedString2", "Receipt")
        updated = updated Or ShowColumnAs(listOfColumns, "UserDefinedString3", "Creditor Purchase")
        If updated Then activeSheet.ApplyXMLDefinition(xmlDocument.OuterXml)
    End Sub

    Private Function ShowColumnAs(listOfColumns As XmlElement, key As String, caption As String) As Boolean
        For Each column As XmlElement In From col As XmlElement In listOfColumns.ChildNodes Where col.SelectSingleNode("Key").FirstChild().Value = key
            If column.SelectSingleNode("Caption").FirstChild().Value = caption And column.SelectSingleNode("Hidden").FirstChild().Value = "0" Then Return False
            column.SelectSingleNode("Caption").FirstChild().Value = caption
            column.SelectSingleNode("Hidden").FirstChild().Value = "0"
            Return True
        Next
        Return False
    End Function

Produces:
grid1.PNG
grid1.PNG (4.58 KiB) Viewed 5162 times


This approach uses UserDefinedString1/UserDefinedString2/UserDefinedString3. There is no UserDefinedCheckbox1 ... is there a way I can jump in with grid event handlers of something to overide the grid display and show a checkbox, and then set UserDefinedString2 (in this case) to "True" or "False" ...
grid.png
grid.png (3.8 KiB) Viewed 5162 times

Re: Grid custom checkbox column

PostPosted: Sun Dec 06, 2015 11:14 am
by Mike.Sheen
In theory if you hook into the readend event from the UI (as in, in the UI add a handler to the business logic readend), you could then set the cell type for each row of the desired columns.

Which form are you attempting to do this in? Let us know and I'll have a crack at it.

Re: Grid custom checkbox column

PostPosted: Tue Dec 08, 2015 11:38 am
by neil.interactit
Hi Mike,

This is on JiwaPurchaseOrdersUI.PurchaseOrders. As an interim measure, I have fudged with toggled text "Yes" and "No" on _purchaseOrderForm.LinesJiwaGrid.CellClick, which gives the functionality in a clunky fashion.

Cheers,
Neil.

Re: Grid custom checkbox column

PostPosted: Sat Feb 27, 2016 5:52 pm
by Mike.Sheen
Bumping as was never marked as solved.

Re: Grid custom checkbox column

PostPosted: Wed Mar 02, 2016 9:44 am
by neil.interactit
Hi Mike,

I deployed the fudge fix, to keep the client happy. I was keeping an eye out for your crack at it, and then intending to update the plugin.

Cheers,
Neil.

Re: Grid custom checkbox column  Topic is solved

PostPosted: Sat Mar 12, 2016 11:21 am
by Mike.Sheen
Attached is a plugin which makes the UserDefinedFloat1 column on purchase orders a checkbox.

POLines_Checkbox.PNG
Column now a Checkbox
POLines_Checkbox.PNG (5.09 KiB) Viewed 5113 times


I just hooked into the ReadEnd of the PO, then set the celltype of the column and then copied that to each cell in the grid:

Code: Select all
    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      var purchaseOrderForm = (JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.MainForm)JiwaForm;
      purchaseOrderForm.PurchaseOrder.ReadEnd += PurchaseOrder_ReadEnd;
    }
   
   private void PurchaseOrder_ReadEnd(object sender, System.EventArgs e)
   {
      var purchaseOrder = (JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)sender;
      var purchaseOrderForm = (JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.MainForm)purchaseOrder.Client;
      
      // change the celltype of the UserDefinedFloat1 column to be a checkbox
      purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Columns["UserDefinedFloat1"].CellType = new FarPoint.Win.Spread.CellType.CheckBoxCellType();
      purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Columns["UserDefinedFloat1"].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
      // copy the celltype and alignment from the column to each cell
      for(int row = 0; row < purchaseOrderForm.LinesJiwaGrid.ActiveSheet.RowCount; row++)
      {
         purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Cells[row, purchaseOrderForm.LinesJiwaGrid.ActiveSheet.GetColumnFromTag(null, "UserDefinedFloat1").Index].CellType = purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Columns["UserDefinedFloat1"].CellType;
         purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Cells[row, purchaseOrderForm.LinesJiwaGrid.ActiveSheet.GetColumnFromTag(null, "UserDefinedFloat1").Index].HorizontalAlignment = purchaseOrderForm.LinesJiwaGrid.ActiveSheet.Columns["UserDefinedFloat1"].HorizontalAlignment;
      }
   }

Re: Grid custom checkbox column

PostPosted: Fri May 27, 2016 11:35 am
by neil.interactit
I had forgotten to tick this one. Awesome Mike, many thanks.