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
Set(ByVal value As String)
SetProperty(CountyListProperty, CountyLst.GetList(Me.DatabaseID, Me.State))
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.
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.
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
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)
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(_countyListProperty, CountyLst.GetList(dbase, state))
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))
Private Set(ByVal value As CountyLst)
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.
Copyright (c) Marimer LLC