//Handle column changing events on the Customers DataGrid table
private void Customers_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { //Only check for errors in the Product column
if (e.Column.ColumnName.Equals("Product")) { //Do not allow "Automobile" as a product
if (e.ProposedValue.Equals("Automobile")) {
object badValue = e.ProposedValue;
e.ProposedValue = "Bad Data";
e.Row.RowError = "The Product column contains an error";
e.Row.SetColumnError(e.Column, "Product cannot be " + badValue);
}
}
}
private void Customers_ColumnChanging(object sender, System.Data.DataColumnChangeEventArgs e) { //Only check for errors in the Product column
if (e.Column.ColumnName.Equals("Product")) { //Do not allow "Automobile" as a product
if (e.ProposedValue.Equals("Automobile")) {
object badValue = e.ProposedValue;
e.ProposedValue = "Bad Data";
e.Row.RowError = "The Product column contains an error";
e.Row.SetColumnError(e.Column, "Product cannot be " + badValue);
}
}
}
解决方案 »
- 请教C#中用工厂模式管理对象时如何调用子类里特有的方法
- c# 回调函数 调自己
- 静态方法这样写为什么不对
- dataGridView1保存更改,提示Update 无法找到 TableMapping['tb_stand']请哪位高手指点一下呀。
- Router纲页自动连接和自动中断连接问题
- detailsview insert状态 dropdownlist 绑定不了
- 一个serialport串口控件的问题
- 问个窗口的显示问题!!
- 求助Visual Studio 2005(winform)配置文件app.config的文件
- 我要在C#桌面程序的form中嵌入word文档,应该怎么做?谢谢!
- 关于int,int.parse ,Convert.ToInt()有何区别??请高手分析一下。
- 100分求助,C#数据库填充代码错误。(在线等)
msdn:
Windows 窗体 DataGrid 控件有两种可用的输入验证类型。如果用户试图输入一个值,而该值具有单元格不可接受的数据类型(例如,向需要整数的单元格中输入一个字符串),则新的无效值将替换为旧值。这种输入验证是自动完成的,不能进行自定义。另一种的输入验证可用于拒绝任何不可接受的数据,例如,在必须大于或等于 1 的字段中输入 0,或者一个不合适的字符串。这是在数据集中通过编写 DataTable.ColumnChanging 或 DataTable.RowChanging 事件的事件处理程序来完成的。以下示例使用 ColumnChanging 事件,因为“Product”列特别不允许不可接受的值。您可以使用 RowChanging 事件来检查“End Date”列的值是否晚于同一行中“Start Date”的值
private void TextBoxLeave(object sender, System.EventArgs e)
{
...
}和datagrid绑定时加:
TxtCol.TextBox.Leave += new System.EventHandler(TextBoxLeave);