Note that there are some explanatory texts on larger screens.

plurals
  1. POIDataErrorInfo with complex types
    primarykey
    data
    text
    <p>I have an Address object defined simply as follows:</p> <pre><code>public class Address { public string StreetNumber { get; set; } public string StreetAddress { get; set; } public string City { get; set; } public string PostalCode { get; set; } } </code></pre> <p>Fairly simple. On the advice an answer to another <a href="https://stackoverflow.com/questions/1401796/idataerrorinfo-in-winforms">question</a> I asked, I am referring to <a href="http://www.codegod.de/WebAppCodeGod/objectdatasource-and-idataerrorinfo-with-winforms-AID427.aspx" rel="nofollow noreferrer">this</a> blog post when databinding my UI to an object of type Person (which contains an Address MailingAddress field).</p> <p>The problem is that the IDataError interface method isn't validating any of the properties of the Address type.</p> <pre><code>public string this[string columnName] { get { string result = null; // the following works fine if(columnName == "FirstName") { if (string.IsNullOrEmpty(this.FirstName)) result = "First name cannot be blank."; } // the following does not run // mostly because I don't know what the columnName should be else if (columnName == "NotSureWhatToPutHere") { if (!Util.IsValidPostalCode(this.MailingAddress.PostalCode)) result = "Postal code is not in a know format."; } return result; } } </code></pre> <p>So, obviously I don't know what the columnName will be... I've stepped through it and it has never been anything other than any of the public properties (of intrinsic types). I've even tried running and breaking on a statement like:</p> <pre><code>if (columnName.Contains("Mailing") || columnName.Contains("Postal")) System.Windows.Forms.MessageBox.Show(columnName); </code></pre> <p>All to no avail.</p> <p>Is there something I'm missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload