dataGridView的一些记录

操作时如果有单元格存在错误,例如新增中存在错误,点击查询,就会出现这种错误:数据错误由于程序无法提交或取消单元格值更改,操作失败。

        //判断是否没选中单元格
            if (this.dataGridView1.CurrentCell != null)
            {
                //判断选中行是否显示出错误
                if (dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].ErrorText != "")
                {
                    dataGridView1.Rows.RemoveAt(this.dataGridView1.CurrentCell.RowIndex);
                }
                //判断是否只有一行新增的数据,第一列为隐藏ID,ID为空则是新增行
                if (dataGridView1.Rows.Count == 1)
                {
                    if (dataGridView1.Rows[0].Cells[0].Value == null || dataGridView1.Rows[0].Cells[0].Value.ToString() == "")
                    {
                        dataGridView1.Rows.RemoveAt(0);
                    }
                }
            }

 

dataGridView1.NewRowIndex;//识别是否有新增行,没有的话返回,我是代码新增行,可能未被识别,没用上

posted @ 2013-12-24 17:48  泥称  阅读(583)  评论(0)    收藏  举报