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. js公有、私有、静态属性和方法的区别

          现下,javascript大行其道,对于网站开发人员来说,javascript是必需掌据的一门语言,但随着jquery等框架的流行和使用,许多人对于原生javascript缺乏深入的理解, ...

  2. PLSQL Developer 不能连接 oracle 11g 64位 的解决办法

    http://blog.itpub.net/14184018/viewspace-760730 http://www.cnblogs.com/gulvzhe/archive/2012/08/27/26 ...

  3. 【Oracle】Oracle 11g 64位安装完后,ora-12541错误和ora-12514错误的解决

    问题描述: 干净的windows2008 64位服务器上安装 oracle 11g R2 64bit服务端,安装完后,NetManager中默认的主机名为localhost,可以测试通过.但是无法在别 ...

  4. 盐水的故事[HDU1408]

    盐水的故事Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  5. Angular JS中的依赖注入

    依赖注入DI angularjs中与DI相关有angular.module().angular.injector(). $injector.$provide. DI 容器3要素:服务的注册.依赖关系的 ...

  6. Windows下查看端口冲突的进程

    在tomcat部署中,经常遇到80端口被占用,下面总结了两条查看端口进程的方法. 查看端口方法: netstat -aon|findstr "80"   如图,使用80端口的进程列 ...

  7. android 第三方 图表

    1.XCL-Charts 直接利用Canvas api画出图形,各有好处. XCL-Chart尽量把图的绘制逻辑封装在类中,而把绘制相关的各 个元素开放出来,目的是在保证开发效率的同时,给程序员足够多 ...

  8. Leetcode Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  9. CSS z-index 属性的使用方法和层级树的概念

    之前有一篇文章提到过z-index,我们知道只有在元素设置了position部位static时才生效,而且z-index也跟父元素有关系,今天就在ie7遇到类似问题,在网上查了一些资料,发现一篇好文章 ...

  10. asp.net mvc route 中新发现的小技巧

    在发现这个小技巧之前,我经常被某些问题困扰,我们以博客园为例 1:是分类名称 2:是分类url 3:点击分类,进入的页面,要显示分类的名称 4:点击分类,进入的页面,要用分类相关参数 在日常web的开 ...