Introduction to common Interfaces

IDataErrorInfo

Provides the functionality to offer custom error information that a user interface can bind to.

.NET Framework Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile Supported in: 4, 3.5 SP1

Example 1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace IDataErrorProviderExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//var person = new Person();
var person = new Person { Age = };
//var person = new Person { Age = 200 };
//ageTextBox.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnPropertyChanged, null, "No");
ageTextBox.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnPropertyChanged); //case 1
errorProvider1.DataSource = person; //case 2
//errorProvider1.SetError(ageTextBox, "==="); //temp
}
} public class Person : IDataErrorInfo
{
private int age; public int Age
{
get { return age; }
set { age = value; }
} public string Error
{
get
{
//check validation on every property
return "";
}
} public string this[string name]
{
get
{
string result = null; switch (name)
{
case "Age":
if (this.age < || this.age > )
{
result = "Age must not be less than 0 or greater than 150.";
}
break;
default:
break;
} return result;
}
}
}
}

Interface => IDataErrorInfo的更多相关文章

  1. ASP.NET MVC下的四种验证编程方式

    ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表,但是在真正执行目标Action方法之前,还需要对绑定的参数实施验证以确保其有效性,我们将针对参数的验证成为Model绑定 ...

  2. Model的验证

    ModelValidator与ModelValidatorProvider ModelValidator public abstract class ModelValidator { public v ...

  3. WPF Input Validation Using MVVM

    Data validation is a key part in WPF.Validation is used to alert the user that the data he entered i ...

  4. angular2系列教程(七)Injectable、Promise、Interface、使用服务

    今天我们要讲的ng2的service这个概念,和ng1一样,service通常用于发送http请求,但其实你可以在里面封装任何你想封装的方法,有时候控制器之间的通讯也是依靠service来完成的,让我 ...

  5. 接口--interface

    “interface”(接口)关键字使抽象的概念更深入了一层.我们可将其想象为一个“纯”抽象类.它允许创建者规定一个类的基本形式:方法名.自变量列表以及返回类型,但不规定方法主体.接口也包含了基本数据 ...

  6. Configure a bridge interface over a VLAN tagged bonded interface

    SOLUTION VERIFIED February 5 2014 KB340153 Environment Red Hat Enterprise Linux 6 (All Versions) Red ...

  7. Create a bridge using a tagged vlan (8021.q) interface

    SOLUTION VERIFIED April 27 2013 KB26727 Environment Red Hat Enterprise Linux 5 Red Hat Enterprise Li ...

  8. Configure a bridged network interface for KVM using RHEL 5.4 or later?

    environment Red Hat Enterprise Linux 5.4 or later Red Hat Enterprise Linux 6.0 or later KVM virtual ...

  9. Set up VLAN (802.1q) tagging on a network interface?

    SOLUTION VERIFIED October 13 2015 KB39674 KB741413 environment Red Hat Enterprise Linux 4 Red Hat En ...

随机推荐

  1. Codeforces Round #334 (Div. 2)

    水 A - Uncowed Forces #include <bits/stdc++.h> using namespace std; typedef long long ll; const ...

  2. java-数字类

    浏览以下内容前,请点击并阅读 声明 对于6种基本的数字类型,java提供了相对应的类.Number类和六种细分的子类.

  3. jquery上传文件控件Uploadify

    基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. 要求使用jquery1.4或以上版本,flash player 9.0.24以上. 有两个 ...

  4. ACM: 限时训练题解-Runtime Error-二分查找

    Runtime Error   Bahosain was trying to solve this simple problem, but he got a Runtime Error on one ...

  5. [Leetcode] Merge Intevals

    Question: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3], ...

  6. SQL中union运算操作的理解

    在SQL中,对于并运算,可以使用union关键字. 例如: SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FRO ...

  7. PHP面向对象学习三 类的抽象方法和类

    一个类中至少有一个方法是抽象的,我们称之为抽象类. 所以如果定义抽象类首先定义抽象方法. 1.类中至少有一个抽象方法 2.抽象方法不允许有{ } 3.抽象方法前面必须要加abstract 抽象类的几个 ...

  8. python 之redis

    redis是一个key-value存储系统,与memcached类似,它支持存储到value类型相对更多,包括string(字符串),list(列表),set(集合),zset(sorted set ...

  9. Perform UPSERT / INSERT OR UPDATE against a SQLite Database

    Option 1: You can afford deleting the row In other words, you don't have foreign key, or if you have ...

  10. HttpWebRequest Post callback

    public void GetValueFromRequest(string postData) { var request = (HttpWebRequest) WebRequest.CreateH ...