Hi,
I build in Winforms forms for editing master data, means entities.
And I change form caption or groupcontrol caption based on data I get from current entity. If I move to another entity or edit and save current one, then caption is always in sync with current entity.
I hook on bindingsource CurrentItemChanged event, when it is fired, then I reread data into caption.
Everything works fine, except situation when I need to show in caption data from related entity. When the form is opened and data are loaded by
adapter.FetchEntityCollection(ecol, Nothing, 0, Nothing, prefetchPath)
then CurrentItemChanged is fired 3x times (known fact) but in all three cases related entity is nothing.
It means you fire ListChanged event right after loading entitycollections but before you merge related entities into root EC.
Therefore I have to run BindingSource.ResetCurrentItem() after FetchEntityCollection in order to get fired CurrentItemChanged again. This time it has also merged related entities and caption could read data.
For example say I want to edit Order and I want to see in form caption or form's groupcontrol caption: "CustomerName - OrderNo"
I will fetch Orders into entitycollection with prefetch path to Customers
Right after fetching data the event CurrentItemChanged is fired 3x but in all these there cases Order.Customer is Nothing because Customers are not merget into Orders yet.
Therefore something like Caption=Order.Customer.CustomerName & "-" & Order.OrderNo
will not work right after the data load. Therefore I have to call BindingSource.ResetCurrentItem() after fetching data
I hope it is more clear to you. Simply said I think you should fire ListChanged AFTER you merge entities with related entities. This way I can avoid calling BindingSource.ResetCurrentItem() after initial load.