如何将datagridview中某个单元格的值清空c# [编程] 当在单元格中输入数据时 进行验证,当验证有误时就 将您输入单元格的数据清空(或将输入的数据选中)!急急急急急急……希望高手给我明确的代码!谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dataGridView1.Rows[2].Cells["列名"].Value = String.Empty; dataGridView1.Rows[0].Cells[0].Value = "1";第1行第1列. 添加一个dataGridView控件,命名为dgv//模拟判断结果的变量bool judgeResult=true;public Form1() { InitializeComponent(); dgv.Rows[0].Cells[0].Value = 1; dgv.Rows[0].Cells[1].Value = "Kensou"; //接下来清空第一行第一个单元格的内容,即1 if(judgeResult) dgv.Rows[0].Cells[0].Value = null; } 没有试,不知道这样行不~~dataGridView有一个dataError()事件,dataGridView1.selectedCell.Value="" private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if ("验证有误") this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = null; } private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { //GoodsNum 为定义的该单元格的名称; if (this.dataGridView1.CurrentCell.OwningColumn.Name == "GoodsNum") { ((TextBox)e.Control).TextChanged += new EventHandler(textBox2_TextChanged); } } private void textBox2_TextChanged(object sender, EventArgs e) { //ValidateClass 为判断该输入的数据是否为数字! ValidateClass validateclass = new ValidateClass(); if (this.dataGridView1.CurrentCell.OwningColumn.Name == "GoodsNum") { if (validateclass.validateNum(aa)) { } else { MessageBox.Show("您输入的格式有误!"); } } } 我需要当弹出对话框出来时,同时将该输入的值 进行清空!你高手给我答案!急急急急急…… 其实上面都是你要的答案了...你只要想办法找到你要删除的某一行某一列 然后把Value 设置为空就好吗?MessageBox.Show("您输入的格式有误!"); dataGridView1.CurrentRow.Cells["GoodsNum"].Value = "";实在不行MessageBox.Show("您输入的格式有误!"); ((TextBox)sender).Text = ""; //不知道行不行 ((TextBox)sender).Text = ""; //不知道行不行上边的都不能清空,反而 这一句能成功!谢谢了 c#窗体边界小问题 类和对象的区别,急啊~~~~ 请问DATAGRIDVIEW里面如何设置CELL的输入格式 请问如何转换将参数Stream可转为MemoryStream? Server Error in '/' Application 听说.NET开源了 可有人知道源代码到哪里下 如何从一个color对象创建一个新的color对象,要求新对象比原来的要“亮”一点。谢谢! 这个查询时间段语句的"table7"在哪?? 在 C# 里面怎样执行一个外部命令? 如何用sql语句向数据库中插入包含特殊字符的文本呢 请教xml处理问题--序列化与dom比较 怎么快便地获取数据表中某字段的最大值?
bool judgeResult=true;
public Form1()
{
InitializeComponent(); dgv.Rows[0].Cells[0].Value = 1;
dgv.Rows[0].Cells[1].Value = "Kensou"; //接下来清空第一行第一个单元格的内容,即1
if(judgeResult)
dgv.Rows[0].Cells[0].Value = null;
}
dataGridView1.selectedCell.Value=""
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if ("验证有误")
this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = null;
}
{
//GoodsNum 为定义的该单元格的名称;
if (this.dataGridView1.CurrentCell.OwningColumn.Name == "GoodsNum")
{
((TextBox)e.Control).TextChanged += new EventHandler(textBox2_TextChanged);
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
//ValidateClass 为判断该输入的数据是否为数字!
ValidateClass validateclass = new ValidateClass();
if (this.dataGridView1.CurrentCell.OwningColumn.Name == "GoodsNum")
{
if (validateclass.validateNum(aa))
{ }
else
{
MessageBox.Show("您输入的格式有误!");
}
}
}
我需要当弹出对话框出来时,同时将该输入的值 进行清空!你高手给我答案!急急急急急……
MessageBox.Show("您输入的格式有误!");
dataGridView1.CurrentRow.Cells["GoodsNum"].Value = "";实在不行
MessageBox.Show("您输入的格式有误!");
((TextBox)sender).Text = ""; //不知道行不行
上边的都不能清空,反而 这一句能成功!谢谢了