How to bind textbox to BO programmatically


Author
Message
dgsoft
dgsoft
StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
Hi,

I will write little example to display the problem

I have a class



Public class myClass1

Public pmks_BO as myBusinessObject = new myBusinessObject



Private Sub new()

' use factory method to create instance of class

End Sub



Public Shared Function CreateMyClass1(ByVal tnPkId as Integer) as myClass1

Dim loReturn as myClass1 = new myClass1

myClass1.pmks_Bo.Fillbyprimarykey(tnPkId)

Return(myClass1)

End Function



Public Function mmks_ShowWizard() As System.Windows.Forms.DialogResult

Dim loWizard As MKSDokumente_Wizard = New MKSDokumente_Wizard(Me)

Return (loWizard.ShowDialog())

End Function



End class



This class expose some complex logic but kernel of class is a business object and data manipulation



Second step.. button to create object



[Button.Click] code

Dim loMyClass1 as myClass1 = myClass1.CreateMyClass1(1)

loMyClass1. mmks_ShowWizard()





Step 3

Wizard displays a form.. and inside this form I want to make DATABINDING of pmks_BO with form controls.



[Wizard code]





Public Sub New(ByVal tomyClass1 As myClass1)



InitializeComponent()

Me.components.Add(tomyClass1.pmks_BO, "DocumenteBO")

Me._pmks_document = toMKSDokumente

Me.cboProject.BindingField = "fk_proj"

Me.cboProject.BusinessObject = CType(Me.components.Components.Item("DocumenteBO"), myBusinessObject)

Me.cboProject.BusinessObjectEvaluated = True





End Sub





As result.. my controls has no values and databinding not works.

What do I wrong?



Thanks

Denis

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Just a quick note that might help (don't have time to really digest code posted...sorry). To figure out how to programatically bind something (like the combo), the simplest way is to see what code gets generated in the designer file when you manually bind it (via the designer). It turns out that all binding is programatic, its just that normally, the VS IDE does the programming for you (based on how the SF developers created the classes). BigGrin



Just copy and paste the code, then you know what needs to be set and the types etc.
dgsoft
dgsoft
StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
Hi,

Yes.. of course I did absolutely the same. Copy code from designer file and paste to my own Sub..

I thinking I use binding too late in my code.. and some internal StrataFrame databinding mechanism not able to use my new settings.. Maybe exist a way to refresh databinding.. or call some method after databinding changed?

No idea.. but my code works without errors, but values of my controls empty and not react on businessobject edit state



Denis
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
After taking a bit more careful look at your code, I'm wondering if they Type of BO your using is always the same. I.e. Is the BO being bound to always of type "myBusinessObject" (from your code)?



If this is the case, then I'd suggest two things:



1. Drop an instance of myBusinessObject onto the wizard and bind normally.

2. Rather than attempt to change the BO the objects are bound to, just copy the data from the one passed into the form into the one dropped on the form using CopyDataFrom() method. I'd do this during parent form loading event of the BO on the form, so you can control when the BO gets filled, vs. any combos.



'-- Other code the same...just in wizard code make changes...

''' <Summary>

''' Construct a new instance using data from tomyClass1...

''' </Summary>

Public Sub New(ByVal tomyClass1 As myClass1)

'-- DocumentBO is now initialized in InitializeComponent as it

' was dropped on the form at design time. Also all binding

' was handled at design time and is also setup there as well.

InitializeComponent()



'-- Save reference to BO in tomyClass1.

_sourceBO = tomyClass1.pmks_BO

End Sub



''' <Summary>

''' Field to hold BO passed in via tomyClass1 (property in actual code).

''' </Summary>

private _sourceBO As myBusinessObject



''' <Summary>

''' Handle parent form loading and copy data from source BO to local BO.

''' </Summary>

Private Sub DocumentBO_ParentFormLoading() Handles Me.DocumentBO.ParentFormLoading

Me.DocumentBO.CopyDataFrom(_sourceBO, BusinessCloneDataType.ClearAndFillFromCompleteTable)

End Sub



dgsoft
dgsoft
StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)StrataFrame User (145 reputation)
Group: StrataFrame Users
Posts: 93, Visits: 236
Hi,

So - the idea is make a copy of the data between class and wizard form looks good... untill not possible to find way to bind form to existing BO instance.

this is another way Smile) and looks like an interesting idea..



when I save data in wizard - I will re-request data in my class.. well... it seems solution..



Thanks for the idea!



Denis
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad it helped! BigGrin
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search