Getting broken rules for individual property

Getting broken rules for individual property

Old forum URL: forums.lhotka.net/forums/t/4384.aspx


vdhant posted on Thursday, February 21, 2008

Hi guys
I was just wondering if anyone has any idea (and i might have missed something so it might be really obvious) how to get the broken rules for an individual property. What i would like to have is a tool tip that lists the broken rules for an individual field on the form as well as the main list of rules. Also in addition to this whether an individual property is valid or not.

I know I would loop through the broken rules collection for this information but it seems like a bit of a roundabout way of doing it.

 
Thanks
Anthony

JonnyBee replied on Thursday, February 21, 2008

Databinding actually uses the interface System.ComponentModel.IDataErrorInfo which is also implemented by CSLA BusinessObjects - but you must explicitly cast your object to the interface in order to use these methods.

Using this interface you can get error messages for a given Item (Property) or Error (the entire object). It is this interface that the ErrorProvider control uses to get broken rules messages for a given property in a form.

More info on this interface is available here:
http://msdn2.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo_members.aspx

/jonny

vdhant replied on Thursday, February 21, 2008

Hey Jonny
Thanks for the reply. I have seen this interface and know what you are getting at but the problem is that this only returns the first message. I need the list of errors/messages avaiable so that i can use them.
Any ideas on doing this??
Thanks
Anthony

JoeFallon1 replied on Thursday, February 21, 2008

In CSLA 2.x there is this method: (not sure about what is CSLA 3.x yet.)

Public Overloads Function ToString(ByVal severity As RuleSeverity) As String
 
Dim result As New System.Text.StringBuilder()
 
Dim item As BrokenRule
 
Dim first As Boolean = True

  For Each item In Me
   
If item.Severity = severity Then
     
If first Then
       
first = False
     
Else
       
result.Append(Environment.NewLine)
     
End If
    
result.Append(item.Description)
    
End If
 
Next

  Return result.ToString
End Function

1. You  can write a similar method and pass in a Property name instead of a rule severity. By adding a new method to CSLA you always have access to it.

2. Suggest the above to Rocky - so you do not have to maintain it. <g>

Joe

 

RockfordLhotka replied on Thursday, February 21, 2008

var broken = from r in this.BrokenRulesCollection where r.Property = IdProperty.Name select r;

Copyright (c) Marimer LLC