如何在C#中验证datagridview单元 [英] how to validate datagridview cell in C# a
问题描述
我的datagridview之类的东西..this ...
约会日期
1 1/1/2005星期一
2 7/1/2005星期一
3 14/1/2005星期一
4 21/1/2005星期一
用户可以将日期14/1/2005更改为不少于= 7/1/2005且不得大于=大于21/1/2005
您能帮助我进行验证吗???????
感谢和问候
Lakhan
您需要编写验证日期的逻辑,例如.
void dataGridView1_CellValidating( object 发送者,DataGridViewCellValidatingEventArgs e) { DateTime StartDate = " ; DateTime EndDate = " DateTime enetedDate = dataGridView1.Rows [e.RowIndex] .Cells [" ]; 如果(enetedDate > = StartDate&&enetedDate< = EndDate) { // 您的逻辑应该在这里. } 其他 { MessageBox.Show(" ); e.Cancel = true ; } }
注意: 请先使用DataType转换,然后再使用.因为我还没有实现.
谢谢,
Imdadhusen
尝试以下链接:
如何:在Windows窗体DataGridView单元中托管控件
演练:在Windows窗体DataGridView控件中验证数据
如何:验证Windows窗体DataGridView控件中的数据
<您可以使用RangeValidator
控件在其中设置minimumvalue="7/1/2005"
和maximumvalue="21/1/2005"
试试
RangeValidator控件 [ ^ ]
my datagridview somethink like ..this.....
sno date day
1 1/1/2005 Monday
2 7/1/2005 Monday
3 14/1/2005 Monday
4 21/1/2005 Monday
user can change date 14/1/2005 to not lessthan= 7/1/2005 and not greater= than 21/1/2005
can u help me what i have to do for this validation???????
thanks and regards
Lakhan
Hi,
You need to write a logic for validating Date like.
void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { DateTime StartDate = "7/1/2005"; DateTime EndDate = "21/1/2005" DateTime enetedDate = dataGridView1.Rows[e.RowIndex].Cells["Date"]; if( enetedDate >= StartDate && enetedDate<= EndDate) { //Your logic should be here.. } else { MessageBox.Show("Invalid Date!"); e.Cancel = true; } }
Note: Please use DataType conversion before use. because i haven''t implemented it.
Thanks,
Imdadhusen
Try the following links:
How to: Host Controls in Windows Forms DataGridView Cells
Walkthrough: Validating Data in the Windows Forms DataGridView Control
How to: Validate Data in the Windows Forms DataGridView Control
you can useRangeValidator
control where you can setminimumvalue="7/1/2005"
andmaximumvalue="21/1/2005"
Try
RangeValidator Control[^]
这篇关于如何在C#中验证datagridview单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!