Interface => IDataErrorInfo
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的更多相关文章
- ASP.NET MVC下的四种验证编程方式
ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表,但是在真正执行目标Action方法之前,还需要对绑定的参数实施验证以确保其有效性,我们将针对参数的验证成为Model绑定 ...
- Model的验证
ModelValidator与ModelValidatorProvider ModelValidator public abstract class ModelValidator { public v ...
- 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 ...
- angular2系列教程(七)Injectable、Promise、Interface、使用服务
今天我们要讲的ng2的service这个概念,和ng1一样,service通常用于发送http请求,但其实你可以在里面封装任何你想封装的方法,有时候控制器之间的通讯也是依靠service来完成的,让我 ...
- 接口--interface
“interface”(接口)关键字使抽象的概念更深入了一层.我们可将其想象为一个“纯”抽象类.它允许创建者规定一个类的基本形式:方法名.自变量列表以及返回类型,但不规定方法主体.接口也包含了基本数据 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题
一.问题描述 在向ASP.NET MVC中整合NHibernate.Spring.NET后,如下管理员与角色关系: 类public class Admin { public virtual strin ...
- Spring Boot 实践折腾记(三):三板斧,Spring Boot下使用Mybatis
http://m.blog.csdn.net/article/details?id=51646658
- R语言常用命令
data() 列出当前已安装包中所有可用的实例数据集 help("name") 查看帮助文档 summary()
- Codeforces 682D Alyona and Strings(DP)
题目大概说给两个字符串s和t,然后要求一个包含k个字符串的序列,而这个序列是两个字符串的公共子序列,问这个序列包含的字符串的总长最多是多少. 如果用DP解,考虑到问题的规模,自然这么表示状态: dp[ ...
- netty-学习笔记
零.socket: http://haohaoxuexi.iteye.com/blog/1979837 一.NIO(1.0)非阻塞 NIO的特点: Buffer,缓冲区 Channel,管道 Sele ...
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest C. CIA Datacenter
C. CIA Datacenter time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Javascript中大括号“{}”的多义性
摘要:本文主要介绍JavaScript中大括号有四种语义作用. JS中大括号有四种语义作用 语义1,组织复合语句,这是最常见的 if( condition ) { //... }else { //.. ...
- ES5中新增的Array方法详细说明
一.前言-索引 ES5中新增的不少东西,了解之对我们写JavaScript会有不少帮助,比如数组这块,我们可能就不需要去有板有眼地for循环了. ES5中新增了写数组方法,如下: forEach (j ...
- Android Properties 存储
1.初始化 private static void initProperties(){ File logFile = new File(Constants.PROGRESS_PROPERTIES); ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...