List Changed Handler (on Item Added) Error

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
mlevi
Posts: 53
Joined: Mon Dec 01, 2014 2:33 pm

List Changed Handler (on Item Added) Error

Post by mlevi »

Hi,
I have added a list changed event handler to the TitleInsuranceCalculations collection, i run my code on the item added event.
Seems though when i try to change a property on the IOrderItem(TitleInsuranceCalculation) in gives me a strange error.
This is the error i am getting: "InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index"
Here is my code:
internal static void NewTitlePremiumUpdates(IList list, ListChangedEventArgs e)
{
IList ExistingTitlePremiums = (IList)list;
IOrderItem CurrentTitlePremium = (IOrderItem)ExistingTitlePremiums[e.NewIndex];
IOrder Order = ((dynamic)CurrentTitlePremium).Root;
dynamic dynOrder = Order;

IOrderInfo orderInfo = Order.ToOrderInfo();
IState State = orderInfo.State;

if (CurrentTitlePremium != null)
{
if (State.Code == "NY")
{
CurrentTitlePremium["Underwriter"]= dynOrder.Underwriters[0]); => Line that is throwing the error.
}

}

}
Thanks
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: List Changed Handler (on Item Added) Error

Post by John Morris »

Please provide the code that hooks up your event handler, as well as the entire call stack of the exception.
John Morris
Sr. Software Architect
SoftPro
mlevi
Posts: 53
Joined: Mon Dec 01, 2014 2:33 pm

Re: List Changed Handler (on Item Added) Error

Post by mlevi »

Here is my code, there are three parts to it:
Event attaching Setup

ListChangedHandlers insuranceCalculations = new ListChangedHandlers

{

SelectorPath = "Title/TitleInsuranceCalculations"

};

insuranceCalculations.ItemAdded = OrderCollectionHandlers.NewTitlePremiumUpdates;



// attach to list changed event

foreach (ListChangedHandlers handlers in listHandlers)

{

IBindingList list = this.Order.DrillDownToScalarContext<IBindingList>(handlers.SelectorPath);

list.ListChanged += handlers.Execute;

}



// The internals of ListChangedHandlers

internal class ListChangedHandlers

{

public delegate void ListChangedAction(IBindingList list, ListChangedEventArgs e);



public string SelectorPath { get; set; }

public ListChangedAction ItemAdded;

public ListChangedAction ItemMoved;

public ListChangedAction ItemChanged;



public void Execute(object sender, ListChangedEventArgs e)

{

IBindingList list = (IBindingList)sender;

switch (e.ListChangedType)

{

case ListChangedType.ItemAdded:

if (this.ItemAdded != null)

{

this.ItemAdded(list, e);

}

break;

case ListChangedType.ItemChanged:

if (this.ItemChanged != null)

{

this.ItemChanged(list, e);

}

break;

case ListChangedType.ItemDeleted:

break;

case ListChangedType.ItemMoved:

if (this.ItemMoved != null)

{

this.ItemMoved(list, e);

}

break;

case ListChangedType.PropertyDescriptorAdded:

break;

case ListChangedType.PropertyDescriptorChanged:

break;

case ListChangedType.PropertyDescriptorDeleted:

break;

case ListChangedType.Reset:

break;

default:

break;

}

}
}

This is the call stack:
at System.Windows.Forms.ListView.ListViewItemCollection.set_Item(Int32 index, ListViewItem value)

at SoftPro.Select.Controls.ListViewEx.bindingList_ListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)

at SoftPro.Select.Controls.BindingSourceEx.OnListChanged(ListChangedEventArgs e)

at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)

at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at SoftPro.EntityModel.ListChangedEventInstance.Fire()

at SoftPro.EntityModel.EntityTransactionContext.<>c__DisplayClass1.<FireEvents>b__0()

at SoftPro.EntityModel.EntitySynchronizationContext.Invoke(Action action)

at SoftPro.EntityModel.EntityTransactionContext.FireEvents()

at SoftPro.EntityModel.EntityTransactionContext.Scope.Dispose()

at SoftPro.EntityModel.EntityExecutionContext.Dispose(Boolean completed)

at SoftPro.EntityModel.EntityExecutionContext.Scope.Dispose()

at SoftPro.EntityModel.Entity`1.SoftPro.EntityModel.IEntity.set_Item(String path, Object value)

at TitleInsuranceCalculation.SoftPro.OrderTracking.Client.Orders.IOrderItem.set_Item(String , Object )

at RsaData.Automation.OrderCollectionHandlers.NewTitlePremiumUpdates(IBindingList list, ListChangedEventArgs e) in C:\Users\ctevel\Documents\Visual Studio 2010\Projects\ScreenShellPackage\RsaData\Automation\OrderCollectionHandlers.cs:line 109

at RsaData.Automation.ListChangedHandlers.Execute(Object sender, ListChangedEventArgs e) in C:\Users\ctevel\Documents\Visual Studio 2010\Projects\ScreenShellPackage\RsaData\Automation\ListChangedHandlers.cs:line 26

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at SoftPro.EntityModel.ListChangedEventInstance.Fire()

at SoftPro.EntityModel.EntityTransactionContext.<>c__DisplayClass1.<FireEvents>b__0()

at SoftPro.EntityModel.EntitySynchronizationContext.Invoke(Action action)

at SoftPro.EntityModel.EntityTransactionContext.FireEvents()

at SoftPro.EntityModel.EntityTransactionContext.Scope.Dispose()

at SoftPro.EntityModel.EntityExecutionContext.Dispose(Boolean completed)

at SoftPro.EntityModel.EntityExecutionContext.Scope.Dispose()

at SoftPro.EntityModel.Collections.EntityCollection`2.System.ComponentModel.IBindingList.AddNew()

at System.Windows.Forms.BindingSource.AddNew()

at SoftPro.OrderTracking.SnapSections.TitleInsurancePremiumGridSnapSection.AddPremiumCommand_Invoke(Object sender, EventArgs e)

at SoftPro.Select.Controls.Commands.OleCommandTarget.OnCommandTargetInvoke(InvokeEventArgs e)

at SoftPro.Select.Controls.NativeMethods.CallManagedExec(Guid& pguidCmdGroup, Int32 nCmdID, Int32 nCmdexecopt, Object[] pvaIn, Int32 pvaOut, Func`2 managedInvoke)

at SoftPro.Select.Controls.Commands.OleCommandTarget.ProcessExec(Guid& pguidCmdGroup, Int32 nCmdID, Int32 nCmdexecopt, Object[] pvaIn, Int32 pvaOut)

at SoftPro.Select.Controls.Commands.OleCommandTarget.SoftPro.Select.Controls.NativeMethods.IOleCommandTarget.Exec(Guid& pguidCmdGroup, Int32 nCmdID, Int32 nCmdexecopt, Object[] pvaIn, Int32 pvaOut)

at SoftPro.Select.Controls.NativeMethods.CallComExec(InvokeEventArgs eventArgs, IOleCommandTarget target)

at SoftPro.Select.Managers.CommandManager.TryInvokeRecursively(IntPtr hwnd, InvokeEventArgs eventArgs)

at SoftPro.Select.Managers.CommandManager.Invoke(IntPtr hwnd, InvokeEventArgs e)
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: List Changed Handler (on Item Added) Error

Post by John Morris »

It looks like your code is changing an order item's data during the handling of a list changed event. This causes a scenario where the system's queued events are out of sync with the list contents. What is the use case you're addressing? In other words, what is point of your code and listening for list changes? Maybe I can recommended a better solution.
John Morris
Sr. Software Architect
SoftPro
mlevi
Posts: 53
Joined: Mon Dec 01, 2014 2:33 pm

Re: List Changed Handler (on Item Added) Error

Post by mlevi »

We are looking to automatically set a zone and underwriter on a TitleInsuranceCalculation any time one is added, currently a user needs to select these values manually.
We were thinking it makes the most sense to do this on Item added on the List changed event.
The First Title Insurance Calculation that always comes in with the order, has Underwiter and Zone set via the template.
Our understanding was that a template can take care of the First default Title Insurance Calculation, but not any subsequent ones.
So we added code to set it on the List Changed Event.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: List Changed Handler (on Item Added) Error

Post by John Morris »

That should be doable with custom order rules. Have you looked into that approach?
John Morris
Sr. Software Architect
SoftPro
mlevi
Posts: 53
Joined: Mon Dec 01, 2014 2:33 pm

Re: List Changed Handler (on Item Added) Error

Post by mlevi »

I am trying to implement this.
I have navigated to any order and gone to the specific field i want to add a custom rule on. In my case the field is Underwriter on TitleInsuraceCalculation
I hit Shift-f12 and i get the window for the custom rule.
(I actually also tried doing this on the Invoice Number field on Invoice - the example in the documentation it was not working either)
The thing is i am unable to add a new module as the option when i right click on modules is grayed out.
Also i noticed that the order has an option when you right click on it to make it the default order, what is this referring to?
Thanks
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: List Changed Handler (on Item Added) Error

Post by John Morris »

When opening an order for the purposes of editing the custom order rules (aka Order Modules), you have to open the order in "Design" mode. This is accomplished by holding down the ALT key while opening the order. There isn't a UI hint that will show you that you're in design mode for an order. However, you'll find that the Shift+F12 development studio will now allow you to add modules for that order.

Since most users do not open orders with the ALT key down, the system is able to skip design mode, allowing the app to short circuit certain code paths, thereby speeding up normal order open actions (non-design mode).

As a side note, holding down the CTRL key while opening an order will force it to open in read-only mode. In a similar fashion, you'll notice that opening an order as read-only is very fast compared to opening an order in normal or design mode.
John Morris
Sr. Software Architect
SoftPro
mlevi
Posts: 53
Joined: Mon Dec 01, 2014 2:33 pm

Re: List Changed Handler (on Item Added) Error

Post by mlevi »

Thanks.
I was able to implement a rule.
I am having issues with my second rule.
On a TitleInsuranceCalculation there is a property called ZoneOrArea, it's type is IPolicyZone.
I am trying to set it's value as such:
def TitleInsuranceCalculation_ZoneOrArea_Value(args):
args.Value = "New York Zone 1"
It is not doing anything, i am assuming it it because we need to send the ZoneOrArea a IPolicyZone type.
Is there anyway this can be done through python?
We basically need the ability to set ZoneOrArea on a TitleInsuranceCalculation
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: List Changed Handler (on Item Added) Error

Post by John Morris »

Adding a custom rule to that property (and others similar to it, i.e. drop downs) isn't supported until we release 4.0 SP4 - in the Aug/Sept 2015 timeframe. When released, it will work like the following code snippet. For your use case, the "dropdown list" is not the IProductType, but rather the IPolicyZone. The same principal applies.

Code: Select all

import clr
import System
clr.ImportExtensions(System.Linq)

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Enumerations import *
            
def Order_ProductType_Value(args):
      enums = args.GetService(IEnumManager)
      productTypes = enums.GetEnum[IProductType]()
      test = [pt for pt in productTypes.Values if pt.Name == 'Test']
      if test:
            args.Value = test[0]
John Morris
Sr. Software Architect
SoftPro
Post Reply