Page 1 of 1

Change Jiwa Grid

PostPosted: Sat Apr 28, 2018 2:23 pm
by SBarnes
Hi Mike,

To add a column to a Jiwa Grid you use AddColumn when setting it up, how to do you do the following?

    Remove a column
    Rename a column
    Hide a column

Re: Change Jiwa Grid  Topic is solved

PostPosted: Sat Apr 28, 2018 4:36 pm
by Mike.Sheen
Hi Stuart,

Attached is a plugin for 07.01.00 which demonstrates this.

The code simply adds 3 columns in the Setup method of the FormPlugin class (for the sales order form) then hides, removes and renames one - the renamed one I also populate in a handler for the LineDisplayed event to show it does in fact work:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{   
   JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)JiwaForm;
   
   salesOrderForm.grdLines.AddColumn("Test1", new JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaTextCellType(), "Test1", 8, false, true, true, false, 50, true);
   salesOrderForm.grdLines.AddColumn("Test2", new JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaTextCellType(), "Test2", 8, false, true, true, false, 50, true);
   salesOrderForm.grdLines.AddColumn("Test3", new JiwaFinancials.Jiwa.JiwaApplication.JiwaManageGrid.JiwaTextCellType(), "Test3", 8, false, true, true, false, 50, true);
         
   // Hide a column   
   FarPoint.Win.Spread.Column columnToHide = salesOrderForm.grdLines.ActiveSheet.GetColumnFromTag(null, "Test1");
   salesOrderForm.grdLines.ActiveSheet.Columns[columnToHide.Index].Visible = false;
   
   // Remove a column      
   FarPoint.Win.Spread.Column columnToRemove = salesOrderForm.grdLines.ActiveSheet.GetColumnFromTag(null, "Test2");
   salesOrderForm.grdLines.ActiveSheet.Columns.Remove(columnToRemove.Index, 1);
   
   // Rename a column      
   FarPoint.Win.Spread.Column columnToRename = salesOrderForm.grdLines.ActiveSheet.GetColumnFromTag(null, "Test3");
   columnToRename.Tag = "Test4";
   
   // Add a handler to LineDisplayed to set the renamed Test4 column text to prove it works with new name
   salesOrderForm.LineDisplayed += LineDisplayed;
}

public void LineDisplayed(object sender, System.EventArgs e, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine SalesOrderLine, int Row)
{
   JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)sender;
   salesOrderForm.grdLines.set_GridText("Test4", Row, "New Text");
}


If you plan on removing or renaming our standard columns in any form, then you may have issues with the custom column information being persisted and also the form reacting to change/click events.

Mike

Re: Change Jiwa Grid

PostPosted: Sat Apr 28, 2018 4:40 pm
by SBarnes
Thanks Mike, its actually for a new custom form being added to Jiwa.

Re: Change Jiwa Grid

PostPosted: Sun Apr 29, 2018 9:14 am
by SBarnes
Hi Mike

To finish this off and make it a bit more maintainable for anyone who wants to use it I have created a series of extension methods as shown below in a class, just pasting the code into a plugin will make them available.

Code: Select all
    public static class JiwaGridExtensions
    {

      
      public static void DeleteColumn(this JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid Grid, string ColumnName)
      {
         FarPoint.Win.Spread.Column columnToRemove = Grid.ActiveSheet.GetColumnFromTag(null, ColumnName);
            Grid.ActiveSheet.Columns.Remove(columnToRemove.Index, 1);
      }
      
      
      public static void HideColumn(this JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid Grid, string ColumnName, bool Hide = true)
      {
          FarPoint.Win.Spread.Column columnToHide = Grid.ActiveSheet.GetColumnFromTag(null, ColumnName);
             Grid.ActiveSheet.Columns[columnToHide.Index].Visible = !Hide;
      }
      
      
      public static void RenameColumn(this JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid Grid, string ColumnName , string NewColumnName)
      {
         FarPoint.Win.Spread.Column columnToRename = Grid.ActiveSheet.GetColumnFromTag(null, ColumnName);
            columnToRename.Tag = NewColumnName;
      }
      
      public static void ChangeColumnCaption(this JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid Grid, string ColumnName , string NewCaption)
      {
         FarPoint.Win.Spread.Column columnToRename = Grid.ActiveSheet.GetColumnFromTag(null, ColumnName);
            columnToRename.Label  = NewCaption;
      }      
      
    }

Re: Change Jiwa Grid

PostPosted: Sun Apr 29, 2018 12:05 pm
by Mike.Sheen
SBarnes wrote:To finish this off and make it a bit more maintainable for anyone who wants to use it I have created a series of extension methods as shown below in a class, just pasting the code into a plugin will make them available.


Sweet - and thanks!

For those who don't know about extension methods, it's a way of dynamically adding methods to an object - so with the class Stuart provided, you can now do the following in your code:

Code: Select all
grdLines.DeleteColumn("ColumnName");
grdLines.HideColumn("ColumnName", true);
grdLines.ChangeColumnCaption("ColumnName", "New Caption");


I've found extension methods to be a great way of making code clean and lean - you can add them to any class - so those pesky custom fields we all know and love can have extension methods which map to the custom field value so you can treat them as properties of the owning class.

Mike

Re: Change Jiwa Grid

PostPosted: Sun Apr 29, 2018 12:26 pm
by SBarnes
Hi Mike,

I couldn't get it to work for VB.Net though, I thought putting it in a plugin and then having a vb.net plugin reference the c# plugin would work but unfortunately not, may be you have an idea on how to get that to work?

Re: Change Jiwa Grid

PostPosted: Sun Apr 29, 2018 12:44 pm
by Mike.Sheen
SBarnes wrote:Hi Mike,

I couldn't get it to work for VB.Net though, I thought putting it in a plugin and then having a vb.net plugin reference the c# plugin would work but unfortunately not, may be you have an idea on how to get that to work?


Hi Stuart - worked fine for me in 07.01.00 - both C# and VB.NET.

Attached are 3 plugins - one to add your extension method, one testing it in VB.NET and one testing in C# (don't have both the VB.Net test plugin and c# one enabled at the same time or you won't know which one is doing the hiding).

I'm testing by hiding the column "PartNo" of the sales order entry form grdLines grid - I'm doing this in the Setup method of the FormPlugin class - if you're adding your own column perhaps you're trying to hide it before it was added?

Mike

Re: Change Jiwa Grid

PostPosted: Sun Apr 29, 2018 1:03 pm
by SBarnes
Hi Mike,

It was solved by logging out of Jiwa and logging back in the version of the plugin with the extension methods had been recompiled since Jiwa was opened so I suspect that was causing the issue with my test.

Anyway at the end of it thanks to your efforts there is now a separate plugin for it that will make it work in Vb.Net.