dataGridView数据比较问题
时间:2011-12-27
来源:互联网
CSDN不能连续回复3次,我只能重新开个一张贴了,烦,明天要检查了,大家快快看看该怎么改,谢谢!
第4列的数据是用键盘输入的,然后与第3列数据进行比较,下面是我自己写的,但发现还是会出现第四列对象没有初始化的问题,请问我该怎么改,或者有别的方法能实现吗?谢谢!!
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
bool flag = false;
if (e.ColumnIndex == 4)
{
try
{
if (!String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
flag = true;
decimal val = decimal.Parse(e.FormattedValue.ToString());
}
}
catch (Exception ex)
{
flag = false;
dataGridView1.Rows[e.RowIndex].ErrorText = "必须输入数字";
MessageBox.Show("必须输入数字");
e.Cancel = true;
}
if (flag&&e.FormattedValue.ToString().Trim()!=null)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
decimal d1 = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value.ToString());
decimal d2 = Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value.ToString());
if (d1 > d2)
{
dataGridView1.Rows[i].ErrorText = "实际入库量不能大于订购量";
MessageBox.Show("实际入库量不能大于订购量");
e.Cancel = true;
}
}
}
}
}
作者: abcwlm 发布时间: 2011-12-27
第一.你要把错误的信息贴出来.
第二.Cell数组的下标是从0开始的,第四列就是Cells[3],第三列就是Cells[2],看看有没有弄错.
第二.Cell数组的下标是从0开始的,第四列就是Cells[3],第三列就是Cells[2],看看有没有弄错.
作者: ccy_qty 发布时间: 2011-12-27
if (e.ColumnIndex == 4)?
你要比哪列?
你要比哪列?
作者: lonelypig1 发布时间: 2011-12-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28