I have code like this:
myBO =
DirectCast(myOtherBO.Clone, MyType)'myBO still contains all the Broken Rules from myOtherBO which causes them to appear twice on screen.'Need to clear it.
'JF 6/27/07 - this code does not work.
Dim ruleCollection As Csla2.Validation.BrokenRulesCollection = myBO.BrokenRulesCollection
Dim item As Csla2.Validation.BrokenRule = ValidationRules.GetBrokenRules.Item(index)
For i AsInteger = ruleCollection.Count - 1 To 0 Step -1
item = ValidationRules.GetBrokenRules.Item(i)
ValidationRules.GetBrokenRules.Remove(item)
Next'The code above ends up calling this in ReadOnlyBindingList:ProtectedOverridesSub RemoveItem(ByVal index AsInteger)
IfNot IsReadOnly Then
Dim oldValue AsBoolean = AllowRemove
AllowRemove = True
MyBase.RemoveItem(index)
AllowRemove = oldValue
Else
ThrowNew NotSupportedException(My.Resources.RemoveInvalidException)
EndIf
EndSub
The code fails because IsReadOnly is set to True and cannot be changed externally.
Even if it worked it would probably make a mess of things since this isn't how Rocky clears the broken rules after he calls CheckRules.
He uses an IRuleMethod and also modifies the counters.
FriendOverloadsSub Remove(ByVal rule As IRuleMethod)' we loop through using a numeric counter because
' removing items in a foreach isn't reliable
IsReadOnly = False
For index AsInteger = 0 To Count - 1
IfMe(index).RuleName = rule.RuleName Then
DecrementCount(Me(index))
RemoveAt(index)
ExitFor
EndIf
Next
IsReadOnly = True
EndSub
On a side note - I normally loop backwards over a collection when removing items as this way you are not affected when the index changes on all the items above the one you just removed. Is that a non-issue in this code block for some reason?
Bottom line - I need a way to remove all the broken rules for the cloned BO. And I do not want ot modify Csla directly if I do not have to.
Any ideas?
Joe