如何在c#.net windows应用程序中清除datagridview类型的单元格值? [英] How to clear datagridview typed cell value in c# .net windows application?
问题描述
你好,
如何在c#.net windows应用程序中清除datagridview类型的单元格值?
我的应用程序中有一个datagridview我正在验证datagridview的numneric值,
我正在使用这段代码: -
private void dataGridView1_CellValidating( object sender,DataGridViewCellValidatingEventArgs e)
{
DataGridViewTextBoxCell cell = dataGridView1 [6,e.RowIndex] as DataGridViewTextBoxCell;
if(cell!= null)
{
if(e.ColumnIndex == 6)
{
char [] chars = e.FormattedValue.ToString() .ToCharArray();
foreach(char c in chars)
{
if(char.IsDigit(c)== false)
{
MessageBox.Show(你必须输入仅数字);
e.Cancel = true;
休息;
}
}
}
}
}
}
但是我有一个问题,当我们输入单元格,因此在消息显示后它没有清除单元格,
我必须按,Backspace键清除单元格。
我想在错误输入后自动清除或MessageBox.Show(你只需输入数字);此消息显示。
怎么可能?
请帮帮我。
在此先感谢
Ankit Agarwal
软件工程师
< blockquote>检查以下链接
如何更改DataGridView.CellValidating事件中单元格的值? [< a href =http://social.msdn.microsoft.com/Forums/vstudio/en-US/f127baa3-1a11-4cab-a457-3d52ec476848/how-to-change-the-value-of-a-cell- in-datagridviewcellvalidating-event-target =_ blanktitle =New Window> ^ ]
Hello,
How to clear datagridview typed cell value in c# .net windows application?
I have a datagridview in my application i am validating our datagridview for numneric value,
I am using this code:-
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { DataGridViewTextBoxCell cell = dataGridView1[6, e.RowIndex] as DataGridViewTextBoxCell; if (cell != null) { if (e.ColumnIndex == 6) { char[] chars = e.FormattedValue.ToString().ToCharArray(); foreach (char c in chars) { if (char.IsDigit(c) == false) { MessageBox.Show("You have to enter digits only"); e.Cancel = true; break; } } } } } }
But i have a problem with this, when we typed in cell so it did not clear cell after the message show,
I have to press, Backspace key for clear the cell.
I want to automatically cleared after wrong entry or "MessageBox.Show("You have to enter digits only");" this message show.
How it can be possible?
Please help me.
Thanks in Advance
Ankit Agarwal
Software Engineer
Check Below link
How to change the value of a cell in DataGridView.CellValidating event ?[^]
这篇关于如何在c#.net windows应用程序中清除datagridview类型的单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!