StrataFrame Forum

Business Binding Source DataSource Property

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

By Ertan Deniz - 4/4/2008

Standart Binding Source component has Datasource property. This is used to give a type for the control like a grid in design time. Then, At runtime an instance (Datatable) is binded to a control.

We are using Business Binding Source to bind an object to Devexpress Grid.

In my case, I have an instance object (Companies). But I have to drop that type of object on the form for informing the Devexpress grid. At Design time, I can easily manage the columns etc.

Is there any way to accomplish this without dropping Business Object on the form?

By Trent L. Taylor - 4/4/2008

I am sorry, but I don't totally understand what you are trying to do.  I did understand that you don't want to drop a BO on the form, which is fine.  You can programmatically set a data source to a grid, or any other object for that matter, if you are wanting to create the BO in code and then set it at run-time.  It would just be a matter of setting the DataSource of the grid to a BBS that wraps the BO.  You can create this dynamically in code and then attach it so that you do not have to drop it on a form.
By Ertan Deniz - 4/7/2008

Let me explain.

I have a complex Business Object (Groups) which has a property as another business object (companies).

"Groups" business object comes as a parameter from another form. I can fill Groups.companies. As a result, I have Companies business object
that is not on the form. But If we give the business object or (otherwise the datatable) to a control in designtime, We can manage which columns will be displayed.

Since I don't have "companies" object on the form,I couldn't use this oppurtinity.

There is need to drop a Company Business Object onto the from. But I have one. I want to use that one.

How can I accomplish that feature provided by Binding Source with BBS ? Since I have to use BBS for Devexpress Binding.

By Peter Denton - 4/7/2008

G'day

What you could do is drop a copy of the Companies BO onto the form, drop a BBS onto the form and set the Companies BO as the source, configure the devexpress components to use the BBS to access the fields you want, then delete the copy of the Companies BO. I believe that this will leave all the devexpress bindings in place. Then at run time bind the Groups.companies BO to the BBS. However this would be difficult to maintain and I would not do it!

I suggest that you leave the Companies BO on the form and either copy the datatable from the Groups.Companies BO into it, or maybe ShareCurrentDataTable (which I know nothing about but sounds promising in this instance).

Hope this helps

Peter

By Ertan Deniz - 4/8/2008

Thanks.

I am looking for a solution that there is no two instance of same object.

By Trent L. Taylor - 4/8/2008

Ertan,

You can do this but you will need to use a BBS as Peter was pointing out.  This is exactly what we do for our reports.  We create a class that inherits from a BBS and then expose the BO (this would only be a single instance).  Then that BO exposes another BBS that wraps another BO.  This way you can get exactly what you want.

Public Class OrdersBBS
    Inherits MicroFour.StrataFrame.Business.BusinessBindingSource

#Region " Constructors "

    ''' <summary>
    ''' Default Constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        Me.BusinessObject = New OrdersBO()
    End Sub

#End Region

#Region " Public Methods "

    ''' <summary>
    ''' Populate the data source
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Fill(Byval customerPK As Long)
        If Not Me.DesignMode Then
            CType(Me.BusinessObject, OrdersBO).FillByParentPrimarykey(customerPk)
        End If
    End Sub

#End Region
   
End Class

Public Class CustomersBBS
    Inherits MicroFour.StrataFrame.Business.BusinessBindingSource

#Region " Constructors "

    ''' <summary>
    ''' Default Constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        Me.BusinessObject = New CustomersBO()
    End Sub

#End Region

#Region " Private Fields "

    Private _Orders As New OrdersBBS()

#End Region

#Region " Public Methods "

    ''' <summary>
    ''' Populate the data source
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Fill()
        If Not Me.DesignMode Then
            CType(Me.BusinessObject, CustomersBO).FillTop100()

            '-- You could load the Orders BO in the OrdersBBS here
        End If
    End Sub

#End Region

#Region " Public Properties "

    Public Readonly Property Orders As OrdersBBS
        Get
             '-- You may want to apply a filter here to filter our the orders
             '    for the current customer here
             '_Orders.Filter = "or_cs_pk = " & _Customers.pk.ToString()
             Return _Orders
        End Get
    End Property

#End Region
   
End Class

By Ertan Deniz - 4/8/2008

With this method, I have an OrdersBBS that wraps a Order Business Object.But I still need an Order Object at design time to manage grid columns (i.e properties related to columns)

I can use OrdersBBS property for databinding by assigning it to the BBS dropped on the form or assigning it directly to the Grid.

We have to find new way.

By Trent L. Taylor - 4/9/2008

I can use OrdersBBS property for databinding by assigning it to the BBS dropped on the form or assigning it directly to the Grid.

At this point it is just programming.  If you want to write your BBS class so that you can swap between different Orders BOs or share the same one that is totally up to how you decide to design your application.  Another option would be to create a shared OrdersBO somewhere that gets used by both places.  But this is just more of a design issue that a functionality issue...you can make it go either way with this class.