Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
I have a parent and a child BO on a form. The form needs to take some actions after the child BO has navigated, so in the Navigated event of the child BO, I'm referencing a control. However, I'm getting an error that the control doesn't exist (the reference is nothing) and after much head banging, I realized that this is being run during InitializeComponent! Most likely the control hasn't even been initialized yet. The child BO is configured to have the parent BO and the parent is configured to MatchCurrentRow. I thought I had to manually load BOs during load or in the constructor (after InitializeComponent), and now I find the child is loading during InitializeComponent. What's up? BTW, I have simular needs in the parent BO, which is working just fine.
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
I double checked and the control in question is set. The list box is using CopyDataFrom, with a list populating event to set the BO etc. I'm including the stack trace...
TargetInvocationException
Exception has been thrown by the target of an invocation.
NullReferenceException
Object reference not set to an instance of an object.
Source : mscorlib
Stack Trace:
at MicroFour.StrataFrame.Business.BusinessLayer.CopyDataFrom(BusinessLayerBase BusinessObject, BusinessCloneDataType CopyType)
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at MicroFour.StrataFrame.UI.Windows.Forms.ListControl.PopulateComboFromBusinessObject(IListControl lstControl, Object[] Parameters)
at MicroFour.StrataFrame.UI.Windows.Forms.ListControl.PopulateCombo(Control lstControl, Object[] Parameters)
at MicroFour.StrataFrame.UI.Windows.Forms.ListBox.PopulateCombo(Object[] Parameters)
at MicroFour.StrataFrame.UI.Windows.Forms.ListBox.Requery()
at RAMS_MITA_2.ProjectProcessForm.ProjectProcessTriggerBO1_Navigated(NavigatedEventArgs e) in D:\Projects\FoxSystems\RAMS.NET.StrataFrame\RAMS_2\RAMS_MITA_2\ProjectProcessForm.vb:line 173
at MicroFour.StrataFrame.Business.BusinessLayer.NavigatedEventHandler.Invoke(NavigatedEventArgs e)
at MicroFour.StrataFrame.Business.BusinessLayer.raise_Navigated(NavigatedEventArgs e)
at MicroFour.StrataFrame.Business.BusinessLayer.OnNavigated(NavigatedEventArgs e)
at MicroFour.StrataFrame.Business.BusinessLayer.Navigate(BusinessNavigationDirection Direction, Int32 AbsoluteIndex, Object[] PrimaryKeyValues, Boolean AttemptToCheckRules, Boolean IsRefill)
at MicroFour.StrataFrame.Business.BusinessLayer.set_Filter(String value)
at MicroFour.StrataFrame.Business.BusinessLayer.FilterChildRecords(BusinessLayer ChildBusinessObject)
at MicroFour.StrataFrame.Business.BusinessLayer.set_ChildAutoFilterOption(AutoChildFilterOptions value)
at RAMS_MITA_2.ProjectProcessForm.InitializeComponent() in D:\Projects\FoxSystems\RAMS.NET.StrataFrame\RAMS_2\RAMS_MITA_2\ProjectProcessForm.Designer.vb:line 479
at RAMS_MITA_2.ProjectProcessForm..ctor() in D:\Projects\FoxSystems\RAMS.NET.StrataFrame\RAMS_2\RAMS_MITA_2\ProjectProcessForm.vb:line 25
...
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
This is killing me. Can a form have more than one child on it? I have a table (tblProcess) that has 12 child tables. My preferred way of doing this (and how I was doing it in Access 2K) was to have all of this on one form. However, whenever I put the BO for the second child on the form, it blows up. Any help would be appreciated.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
I'm not sure what you mean by the form blowing up when you put the second child on the form. However, as for the problem in your first two posts, you will need to add some sort of "loaded" flag to the form to indicate when the business object is loaded. Something like this: "Private _ChildBoLoaded As Boolean = False" and in the ParentFormLoading event of the child business object set that flag to True. Then, in your Navigated of the parent (where you're requerying the list), test to make sure the flag is true before actually calling any code within the Navigated event handler.
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Sorry for the snippy posts, I was tired and very frustrated yesterday.
What I meant by "blowing up" was that the debugger would report an error. However, this isn't happening today. I just tried it. sigh. It was that kind of day yesterday.
However, I would still like to understand what is going on. Why is the child BO loading in the InitializeComponent routine? I thought I had to manually load the BOs, either after InitializeComponent in a constructor or in FormLoad. I not real fond of just putting in a flag without also understanding why I'm putting in the flag.
Thanks!
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
The reason is that during the InitializeComponent, the ChildAutoFilterOption is being set. When that property is set, it cascades the filter to the child business objects, and if the filter changes on the child business objects, then the child business objects call Navigate() so that the bound controls are refreshed to the correct record. So, none of your business objects have any data, yet, but when the ChildAutoFilterOption is being set, it causes one of your business objects to Navigate() and you have an event handler on the Navigated event, which is filling the business object. So, it's being filled prematurely. It's just like adding a handler to a TextBox.TextChanged event and setting the text at design-time. The TextChanged event gets raised when the text is initially set during the InitializeComponent method, and if you have some code in your handler, it might fail because most of the other objects are not yet instantiated, so, you add a flag to let you know when the form has finished loading.
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Thank you! That makes sense. I'm learning tons from you guys! I'll reiterate to make sure I understand. * The Parent BO has its ChildAutoFilterOption set in InitializeComponent (because it was set at design time, via the property sheet). * This cascades the filter to the child business objects (all that have the above BO set as parent). * Changing the filter on a BO causes the Navigate() to fire, which will cause any Navigated event handlers to fire * If the Navigated event handlers are accessing or referring to anything that is not yet initialized yet, BOOM * Use a flag to denote when the form has initialized, all data is loaded and refer to that flag in any child navigated even handlers.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Yes, sir, you got it
|
|
|
Keith Chisarik
|
|
Group: StrataFrame Users
Posts: 939,
Visits: 40K
|
If one changes the ChildAutoFilterOption of a BO from MatchCurrentRow to Off, what needs to be done to clear the filter on the BO? I need to programatically add records to both the parent and child, if I initially have the ChildAutoFilterOption = Off it is fine, if I have it set as MatchCurrentRow then change it programatically to Off to add my data it does not work. Both parent and child have an associated BBS that is the datasource for a datagridview control.
Keith Chisarik
|
|
|
Keith Chisarik
|
|
Group: StrataFrame Users
Posts: 939,
Visits: 40K
|
I got this to work by unhooking by grid from the BBS, manually clearing the BO's filter after the ChildAutoFilterOption gets set to "Off", importing my records and then reset the datagrid's source to the BBS. I would think that setting the ChildAutoFilterOption to Off would clear the BO's filter, it does not. Did I forget to set/call something or working as intended?
Keith Chisarik
|
|
|