Change Jiwa Grid  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Change Jiwa Grid

Postby SBarnes » Sat Apr 28, 2018 2:23 pm

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
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Jiwa Grid  Topic is solved

Postby Mike.Sheen » Sat Apr 28, 2018 4:36 pm

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
Attachments
Plugin Column Functions Test.xml
(33.1 KiB) Downloaded 80 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Jiwa Grid

Postby SBarnes » Sat Apr 28, 2018 4:40 pm

Thanks Mike, its actually for a new custom form being added to Jiwa.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Jiwa Grid

Postby SBarnes » Sun Apr 29, 2018 9:14 am

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;
      }      
      
    }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Jiwa Grid

Postby Mike.Sheen » Sun Apr 29, 2018 12:05 pm

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
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Jiwa Grid

Postby SBarnes » Sun Apr 29, 2018 12:26 pm

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?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Change Jiwa Grid

Postby Mike.Sheen » Sun Apr 29, 2018 12:44 pm

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
Attachments
Plugin Test of csharp Jiwa Grid extension plugin.xml
(32.25 KiB) Downloaded 73 times
Plugin Test of VB.NET grid extensions plugin.xml
(32.51 KiB) Downloaded 79 times
Plugin Jiwa Grid Extensions.xml
(23.32 KiB) Downloaded 74 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Change Jiwa Grid

Postby SBarnes » Sun Apr 29, 2018 1:03 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 21 guests