数据网格视图单元格验证 [英] Data Grid View Cell Validation
本文介绍了数据网格视图单元格验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Visual Studio 2005和SqlServer 2000
我有一个数据网格视图名称为h_card
该网格视图中的4列名为
数字
年
dob
性别
是否有任何方法可以制作截至日期的年份和dob列时间选择器类型IN VISUAL STUDIO 2005.
或
我如何只验证这两列到取值如
MM / DD / YYYY
解决方案
试试这个
私人 Sub Form1_Load(发件人 As System。 Object ,e As System.EventArgs)< span class =code-keyword>句柄 MyBase .Load
DateTimePicker 1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = MM / dd / yyyy
结束 Sub
< blockquote>
dataGridView1.CellBeginEdit + = CellBeginEdit;
private void CellBeginEdit( object sender,DataGridViewCellCancelEventArgs e)
{
DataGridView dgv =(DataGridView)sender;
if (dgv [ 0 ,e.RowIndex] .Value == 2)#或您要检查的任何条件
{
e.Cancel = < span class =code-keyword> true ;
}
其他
{
e.Cancel = false 跨度>;
}
}
I use Visual studio 2005 and SqlServer 2000
I have a data grid view name as h_card
4 columns in that grid view named as
Number
year
dob
gender
Is there any way to make the year and dob column as of date time picker type IN VISUAL STUDIO 2005.
or
How can i validate only these two columns to take the value like
"MM/DD/YYYY"
解决方案
Try this out
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MM/dd/yyyy" End Sub
dataGridView1.CellBeginEdit += CellBeginEdit; private void CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { DataGridView dgv = (DataGridView)sender; if (dgv[0, e.RowIndex].Value == "2") # or whatever conditions you want to check { e.Cancel = true; } else { e.Cancel = false; } }
这篇关于数据网格视图单元格验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文