未在DataGridView中提交的新行 [英] New row not committed in DataGridView

查看:83
本文介绍了未在DataGridView中提交的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我有一个绑定到DataTable的DataGridView:
myDataGridView.DataSource = myDataTable;

用户执行以下操作:


  • 他通过单击DataGridView的最后一行("*")来创建新行。

  • 他填写了这一新行的单元格。

    • 他导航到其他行用鼠标或箭头键。
    • 他保存了myDataTable。结果:新行已丢失。

    推荐答案

    如果用户试图移动到另一行时出现数据错误新行将丢失。一个示例是用户创建新行,并且不填充不允许空值的列的值。防止这种情况的方法是将值分配给datagridview中不允许空值的列 defaultvaluesneeded 事件。另一种方法是处理 DataError 事件。
    If there is an data error when the user tries to move to another row the new row will be lost.  An example is user creates a new row and does not fill in a value for a column that does not allow nulls.  Ways to prevent this is to assign values to columns that do not allow nulls in the datagridview's defaultvaluesneeded event.  Another way is to handle the DataError event.


    这篇关于未在DataGridView中提交的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆