Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
I have an user control that contains couples of controls. I also have a linklabel in this user control that allow user to add new FK record by click on it.
Previously, I used to implement this using childformdialog and it works perfectly. However, that is done on form. How could I have childformdialog in user control also?
Please advice.
Thank you
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
No, when I drop ChildFormDialog on SF user control, VS complaint its parent should be based on baseform. I still can see ChildFormDialog on control tray, but it doesn't work during runtime. And I am sure I am using SF user control because I saw BOTranslation property there.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
It will still work. The message indicates that it is expecting a BaseForm, but it will still work.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
When I run project, error message as shown below prompted. I click on and continue to test my form. I will hit error. After I debug, I found that _ParentForm is always nothing.
From the code in ParentForm(), it seem like _ParentForm is not initialized because of its rootcomponent is not baseform.
Please advice
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
I did not think this error would occur during runtime...sorry about this  But you are right. At the moment this ChildFormDialog relies on having access to a BaseForm. One option is to create the ChildFormDialog in code and manually set the properties and see if it will work for you in that capacity. But at the moment, the ChildFormDialog cannot be dropped directly on a user control. One thing you can do is use the SharedDataTableKey instead in this scenario. If you set the SharedDataTableKey on a BO to the same value on two different instances, they will share the same internal data table. This may be a solution for you in this instance.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, Thank you. I have tried your suggestion to add childformdialog to user control programmatically. It works with condition: 1. ChildFormDialog always refer to ParentForm when GetBusinessObject(). Therefore, I have to drop the same BO on my form also. This way, I have way to "encapsulate" my BO in user control. 2. ChildFormDialog.ParentForm must be set with this.ParentForm (usercontrol.ParentForm) this.CountryFormAddDialog.ParentForm = (BaseForm)this.ParentForm; Hope that is enhancement on this area in upcoming version. I will try out ShareDataTableKey approach later. Stay tuned
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
All you have to do is set the ParentForm property of the ChildFormDialog. this.CountryAddFormDialog.ParentForm = (MicroFour.StrataFrame.UI.Windows.Forms.BaseForm)this.ParentForm; if (this.CountryAddFormDialog.ShowDialog() == DialogResult.OK) { this.cboCountry.SelectedValue = this.countriesBO.CountryID; } So I was right whe I said that you could drop the ChildFormDialog control on the user control. You just have to set the ParentForm property.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
Thank you for clarify.
As I mentioned in my previous post, this "workaround" will still refering BO that located at ParentForm.
Any plan to enable ChildFormDialog to refer to user control so that my user control can work "independently". Once it been dropped on form, my combobox for example in user control population will works without need to remember to drop the same BO on parent form again. The only thing I need to do is set BOTranslation for data binding.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
You can do the same think with a ChildFormDialog on a UserControl as you can with a ChildFormDialog on a form. When you set the business object translations, you can translate the business object on the UserControl to the on on the child form, and if you need to, you can then add the same business object to the parent form and translate it to the one on the UserControl, but you don't have to.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, I tested but I hit error if I don't place the same BO at parent form. Currently, I already set BO in my user control for BO translation. businessObjectTranslationItem1.SourceBusinessObject = "AddressInfo.countriesBO";
And I checked the source code, ChildFormDialog.CreateForm(), it always refer to ParentForm to get BO. '-- Get a reference to the business objects
loSourceBO = GetBusinessObject(_ParentForm, lcSource)
Am I missing something?
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Ah, yes, the _ParentForm references a BaseForm object rather than an IContainerControl object. Are you trying to create an inherited ChildFormDialog that can be dropped on a user control as well? If you do not need the same business object on the parent form, then you probably don't need to use the ChildFormDialog, just show the child form normally using form.ShowDialog().
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
I don't need the same BO at my parentform. But I need the same BO in my user control.
So, do I need to use childformdialog in this case?
Please advice.
Thank you
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
If you are only modifying a single record in the child form, then I would not use the ChildFormDialog and just pass the PK of the record to the child form's constructor. Then, the BO on the child form can call FillByPrimaryKey() and work with it's own copy of the record. If you're passing over lots of records, then you'll need to put the BO on the form and map it as well.
|
|
|