StrataFrame Forum

Accessing a form from 2 different forms with 2 different child-dialogs

http://forum.strataframe.net/Topic31695.aspx

By Thomas Holste - 1/9/2013

Hi there,

I have a form which I want two call from two different forms with two different child-dialogs. Say teher is Form1 with a BO called "BestBo1". I Add a child-dialog, add the same BO to the to-be-calles form and set the properties of the child-sialog. So far, so good.

Now I need the same form for data-entry to called from another form woth a different BO. I do the same, add a child-dialog and the BO ("karteiBo1") and set the properties. I call the form with a new-sub where I pass a parameter to see what form is the parent-form.

In the Load-Event I write something like



If me.cForm = "B"  ' Called from Form 1

   Me.PrimaryBusinessObject = BestBo1

   Me.txtKollege.Businessobject = BestBo1

   Me.txtkollege.BindingField ) BestBo1.Kollege

   ....' some more controls

Else

   Me.PrimaryBusinessObject = KarteiBo1

   Me.txtKollege.Businessobject = KarteiBo1

   Me.txtkollege.BindingField ) KarteiBo1.Kollege

   ....' some more controls

Endif



But this does not wotk. Whether I call it from Form1 or Form2, I get an out-of-range-error.

So can anyone tell me if I am doing something wrong or if that whole approach is wrong.

Thanks in advance

Thomas
By StrataFrame Team - 1/9/2013

No, it doesn't look like your approach is wrong.  We have child forms that are called from multiple places.  Can you post more information on the exception you are receiving.  I would guess that it is an IndexOutOfRangeException.  The type of exception, and the stack trace would be great.
By Thomas Holste - 1/9/2013

Hi,

here it is:

*******************

BusinessLayerException
  The CurrentRow for table '[dbo].[BEST]' could not be evaluated because the CurrentRowIndex is out of range.  Business object record count: 0.  CurrentRowIndex: -1.

Source     : MicroFour StrataFrame Business

Stack Trace:
   bei MicroFour.StrataFrame.Business.BusinessLayer.get_CurrentRow()
   bei GalileoBO.BestBO.get_KOLLEGE() in D:\vb_net\Gal2GL\GalileoBO\GalileoBO\BestBO.Designer.vb:Zeile 612.
   bei Gal2G.KlarneuFRM.KlarneuFRM_Load(Object sender, EventArgs e) in D:\vb_net\Gal2GL\Gal2G\Gal2G\forms\KlarneuFRM.vb:Zeile 197.
   bei System.EventHandler.Invoke(Object sender, EventArgs e)
   bei System.Windows.Forms.Form.OnLoad(EventArgs e)
   bei MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.OnLoad(EventArgs e)
   bei System.Windows.Forms.Form.OnCreateControl()
   bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   bei System.Windows.Forms.Control.CreateControl()
   bei System.Windows.Forms.Control.WmShowWindow(Message& m)
   bei System.Windows.Forms.Control.WndProc(Message& m)
   bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   bei System.Windows.Forms.Form.WmShowWindow(Message& m)
   bei System.Windows.Forms.Form.WndProc(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   bei System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   bei System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   bei System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
   bei System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   bei System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   bei MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.SetVisibleCore(Boolean value)
   bei System.Windows.Forms.Control.set_Visible(Boolean value)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.RunDialog(Form form)
   bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   bei System.Windows.Forms.Form.ShowDialog()
   bei Gal2G.BestMainFRM.TSBKlartext_Click(Object sender, EventArgs e) in D:\vb_net\Gal2GL\Gal2G\Gal2G\forms\BestMainFRM.vb:Zeile 477.
   bei System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   bei System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   bei System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   bei System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   bei System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   bei System.Windows.Forms.ToolStrip.WndProc(Message& m)
   bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   bei Gal2G.G2GStartfrm.ToolStripMenuItem1_Click(Object sender, EventArgs e) in D:\vb_net\Gal2GL\Gal2G\Gal2G\forms\G2GStartfrm.vb:Zeile 136.
   bei System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   bei System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   bei System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   bei System.Windows.Forms.Application.Run(Form mainForm)
   bei MicroFour.StrataFrame.Application.StrataFrameApplication.RunApplication()
***********************************

I should alos mention that I call this form to a record to the underlying BO (BestBO or KarteiBO)

So later on I write



If cForm = "B" Then

BestBO1.Add()

Else

KarteiBO1.Add()

End If

If cForm = "B" Then

BestBO1.Add()

Else

KarteiBO1.Add()

End If



Best regards

Thomas

By StrataFrame Team - 1/9/2013

Thomas, 

What is the Gal2G.KlarneuFRM.KlarneuFRM_Load() method doing on line 197.  The ChildFormDialog control will swap out the references on the control when you call ShowDialog() on it.  The Load event is called after the references have been swapped out, so it looks like you are trying to talk to the business object that was not swapped.  If you intend to use KarteiBO1, it gets swapped by the ChildFormDialog, but not the BestBO1, it will still be empty.  In your Load handler, can you wrap the line or lines with an "If Not BestBO1.IsEmty Then" test to skip using the BestBO1 if your form is using the KarteiBO1?
By Thomas Holste - 1/10/2013

Hi Ben,

thank you for your help. I found an error calling the child-form and now it almost works.

Now as the form is loaded I have another question. As i wrote, I set the properties for the used controls in the load event, which mean that I set the Businessobject and the binding field. When I edit a record I expected the content of the fields to be shown but this happens only when I set the text property too (There are only textboxes on that form)- Is it right that I have to set the text-property too or did I miss something else?

Best regards

Thomas