Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum

CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • WinForm binding combo box

    rated by 0 users
    Not Answered This post has 0 verified answers | 2 Replies | 1 Follower

    Not Ranked
    2 Posts
    Steve posted on Tue, Mar 29 2011 1:28 PM

    I'm trying to implement a solution using the CSLA 4 framework with a WinForm interface.  I have a BusinessBase class that represents an address.  The address class has an editable property for State and County, and read-only lists for States and Counties.  The goal is to have the class refresh the list of counties each time the State property changes.  This way the CountyList contains a list of counties for the current state.  Using the code below, I'm able to make the class rebuild the CountyList each time the State property changes.

    Public Shared ReadOnly StateProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(Function(c) c.State, "State")
        Public Property State() As String
                Return GetProperty(StateProperty)
            End Get
            Set(ByVal value As String)
                SetProperty(StateProperty, value)

                SetProperty(CountyProperty, vbNullString)
                SetProperty(CountyListProperty, CountyLst.GetList(Me.DatabaseID, Me.State))

            End Set
        End Property

    I'm new to the data binding framework and can not figure out how to have the address class notify the WinForm interface that it needs to rebuild (or refresh) the data source of the CountyListBindingSource. Setting the CountyListProperty in the code above, does not trigger an event that I can capture on the interface.  It would seem that I'm missing something simple (method or event) that is available to me to make this happen.  Any suggestions for a newbie?  Thanks.

    All Replies

    Top 10 Contributor
    4,106 Posts
    Andy replied on Tue, Mar 29 2011 5:40 PM

    Don't call the SetProperty for your Country or CountryList propery in the setter of the State.  Instead, create a business rule which does those functions; Country and CountryList would then be listed as AffectedProperties, which I believe should cause the refresh.

    Not Ranked
    2 Posts
    Steve replied on Wed, Mar 30 2011 12:51 PM

    My attempt to implement a business rule to reset the county properties was not successful.  I added a business rule for the StateProperty that accepts the county name and county list properties.  The rule is changing the county name property to vbnullstring and reloading the correct list of county names,  Furthermore, the text property for the county combo box is changing to nullstring, but once again the interface is not updating the list of values that are bound to the county combo box.  This is the business rule class.

        Private Class ResetCounty
            Inherits BusinessRule

            Dim _countyProperty As Core.IPropertyInfo
            Dim _countyListProperty As Core.IPropertyInfo
            Dim _databaseProperty As Core.IPropertyInfo

            Public Sub New(ByVal stateProperty As Core.IPropertyInfo,
                           ByVal countyProperty As Core.IPropertyInfo,
                           ByVal countyListProperty As Core.IPropertyInfo,
                           ByVal databaseProperty As Core.IPropertyInfo)


                _countyProperty = countyProperty
                _countyListProperty = countyListProperty
                _databaseProperty = databaseProperty

                InputProperties = New List(Of Csla.Core.IPropertyInfo)



            End Sub

            Protected Overrides Sub Execute(ByVal context As Csla.Rules.RuleContext)

                Dim state As String = context.InputPropertyValues(PrimaryProperty)
                Dim dbase As Enum_Database = context.InputPropertyValues(_databaseProperty)

                context.AddOutValue(_countyProperty, vbNullString)
                context.AddOutValue(_countyListProperty, CountyLst.GetList(dbase, state))

            End Sub

        End Class

    Is it possible that my CountyListProperty definition is incorrect?     

    Public Shared ReadOnly CountyListProperty As PropertyInfo(Of CountyLst) = RegisterProperty(Of CountyLst)(Function(c) c.CountyList, "CountyList")
        Public Property CountyList() As CountyLst
                If FieldManager.FieldExists(CountyListProperty) = False Then
                    LoadProperty(CountyListProperty, CountyLst.GetList(Me.DatabaseID, Me.State))
                End If
                Return GetProperty(CountyListProperty)
            End Get
            Private Set(ByVal value As CountyLst)
                SetProperty(CountyListProperty, value)
            End Set
        End Property

    Again, it appears like the list is repopulated as expected, but there is no event handled on the interface to instruct the form to update the DataSource for the combo box control.

    Page 1 of 1 (3 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems