How to setup an SF User Control


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I have several fields like Street, City, State, etc. that are named the same in several tables, so different BO will have the same field names.

I have one form where I have the need to modify the same fields above but for different BOs.  I though that this would be the case to use a User Control, so I created one base on MicroFour.StrataFrame.UI.Windows.Forms.UserControl, then I implemented IBusinessBindable.  Here is where I am confuse, I need to bind several fields, so should I add a property to this user control for each field that needs to be bind?

I have been checking the PeopleLookupControl.vb in StrataFlix but in that sample only one control is basically bound and still it is not clear to me.

Here is screenshot of the user control:

Please advise if I am going in the wrong direction here.

Thanks!



Edhy Rijo

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
A single field will update multiple BOs? If so, then it won't be as easy as just plugging in the binding values, you'll have to do much of it manually.

If you are going to have seperate address fields for each BO, then the binding would be more straight forward. You could even use panels to only show one set of fields at a time, if that makes sense for your requirements. 

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
This is an interesting problem. I wasn't sure how to go about it, so I ended up trying several things in a little sample project. The final solution was quite easy. The key was to NOT attempt to bind the user control, but rather pass in a BO which would get bound instead.



The user control has a BusinessObject property that is of type BusinessLayer. In the setter of that property, you set the value of the bound BO for each of the controls that are bound within the user control. Since the field names are the same and the BindingField property is a string, you can just set the name in the designer for each of the bound controls in the user control. When you drop the user control on a form, you just need to set the BusinessObject property to the appropriate instance on your form. Done.



See the attached sample. It uses a "name" control. I have two BOs, both going to the same Customers table, but because BOs isolate the db from the code, it makes no difference. Two forms use the user control, each using a different BO.



Note there are the remnants from some other tries, none of which worked well (I tried using an abstract base class and then an interface, hence the name of the project).



Hope this helps!
Attachments
TestAbstractVsInterfaceBO.zip (134 views, 788.00 KB)
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Dustin, Greg,

Thanks, I know this is not a normal stuff, and I would have finished by doing a 2nd form or using a panel as suggested by Dustin, but this is more of a challenge exercise that can be very useful in the long run.

Greg, thanks for taking the time to create the sample project, I will play with it right now.

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Greg,

After reviewing your sample, it all was much clear to me and in fact it worked pretty well.  One thing different in my designed is that the same user control is used with 2 BOs one at a time, so I had to manage that in the form where the user control is used and assign the proper BO instance.

Of course this kind of solution may no be the easiest or the most practical, but it is always good to know how to go deep in the code to make it work.

For the sake of others, here is the final code for the User Control class:

Imports System.ComponentModel

Imports FixTrack.Business

Namespace UI.Windows.Forms

     Public Class QBCustomerInfo

#Region " Constructors "

     Public Sub New()

          Me.InitializeComponent()

     End Sub

#End Region

 

#Region " Private Fields "

     Private _BusinessObject As MicroFour.StrataFrame.Business.BusinessLayer

     Private _CustomerNameText As String

#End Region

 

#Region " Public Properties "

     ''' <summary>

     ''' Define the base business object.

     ''' </summary>

     ''' <value></value>

     ''' <returns></returns>

     ''' <remarks></remarks>

     <Category("StrataFrame: Framework")> _

     <Description("Set the BusinessObject that will supply the name data.")> _

     Public Property BusinessObject() As MicroFour.StrataFrame.Business.BusinessLayer

          Get

               Return _BusinessObject

          End Get

          Set(ByVal value As MicroFour.StrataFrame.Business.BusinessLayer)

               _BusinessObject = value

               '-- Bind to our user controls to this BO

               If value IsNot Nothing Then

                    If value.GetType Is GetType(bizCustomers) Then

                         Me.tgbGeneralInfo.Title = "FixTrack Customer record information"

                         Me.txtCustomerName.Enabled = True

                         Me.txtCustomerName.BusinessObject = value

                         Me.txtCustomerFax.BusinessObject = value

                    Else

                         Me.tgbGeneralInfo.Title = "FixTrack Building Address record information"

                         Me.txtCustomerPhone.BindingField = "SuperPhoneNumber"

                    End If

                    Me.txtCustomerName.Enabled = False

                    Me.txtCustomerStreet.BusinessObject = value

                    Me.txtCustomerCity.BusinessObject = value

                    Me.txtCustomerZip.BusinessObject = value

                    Me.txtCustomerPhone.BusinessObject = value

                    Me.txtQB_RefID.BusinessObject = value

                    Me.txtCustomereMail.BusinessObject = value

               End If

     End Set

End Property

 

''' <summary>

''' This property is used to update the Customer Name textbox

''' </summary>

''' <value></value>

''' <returns></returns>

''' <remarks></remarks>

Public Property CustomerNameText() As String

     Get

          Return _CustomerNameText

     End Get

     Set(ByVal value As String)

          _CustomerNameText = value

          Me.txtCustomerName.Text = _CustomerNameText

      End Set

End Property

#End Region

     End Class

End Namespace

Thanks Greg!

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad you got it working! 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