C#窗口应用程序中的Datagrid View问题 [英] Datagrid View Problem in C# window application

查看:88
本文介绍了C#窗口应用程序中的Datagrid View问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,





我有datagridview,我通过查询分配数据源。

in那一列 - 数量可编辑&其格式设置为0.00来自格式化事件。



现在,如果用户删除任何值&直接点击取消按钮然后它会给出如下错误。



操作未成功,因为程序无法提交或退出单元格值更改。



在取消记录中,我们必须调用FillGrid(),其中第一行代码如下,



dgv.Datasource = null



在上面的行中它会抛出错误。



我们还使用了_CellValidating事件正在检查用户是否输入了正确的值。



预先感谢您的帮助



问候,

开发人员

Hello ,


I have datagridview in which i am assigning datasource through query.
in that one column - Quantity is editable & its Format is set 0.00 from cellformating event.

Now if user delete any value & direct click on Cancel Button then it gives error as below.

"Operation did not succeed because the program cannot commit or quit a cell value change."

In Cancel Record we have to call FillGrid() in which first line code is as below ,

dgv.Datasource = null

In above line it throws error.

Also We have used _CellValidating Event in which we are checking whether user has entered proper value or not.

Thanks in Advance for help

Regards,
Developer

推荐答案

只是一个猜测,但在调用 dgv.CancelEdit()之前将数据源设置为null可能有所帮助。
Just a guess but calling dgv.CancelEdit() before setting the datasource to null might help.


在网格中的每个单元验证中检查代码中的逻辑,并在需要时应用验证,否则跳过验证并将默认值设置为特定单元格。



1)当我们更改单元格中的任何值并且它与单元格的数据类型不匹配时,时间网格会引发错误。

2)当我们在单元验证事件上写e.Cancel = True,然后我们尝试更改网格的数据源,同时也输出相同的错误。
Check your logic first in your code for every cell validation in grid and apply validation whenever it is required otherwise skip that validation and set default value to particular cell.

1)When we change any value in cell and it is not match with the datatype of cell that time grid throws an error.
2)When we write e.Cancel = True on cell validation event and then we try to change the data source of grid that time also same error throws.


我在以下情况下遇到此错误:



1.有一排20行。

2.我的活动单元格在第10行。

3.我会根据我的简单查找功能将网格过滤到少于10行的内容。

4.这导致错误,因为当前的单元格地址不再存在。



现在你认为网格足够聪明,可以将当前单元格移动到可用的位置 - 但似乎它没有这样做。 br />


我的修复方法是在更改行数之前将当前单元格设置为第一列和第一行:



I was getting this error in the following case:

1. Have a grid of say 20 rows.
2. My active cell was on say row 10.
3. I would filter the grid down to something less than 10 rows based on a simple find feature I have.
4. This caused the error because the current cell address no longer existed.

Now you'd think the grid would be smart enough to move the current cell to something that is available - but it seems that it doesn't do this.

My fix is to just set the current cell to the first column and first row before changing the number of rows:

dgv.CurrentCell = dgv[0, 0];





我解决了这个问题。



That solved this problem for me.


这篇关于C#窗口应用程序中的Datagrid View问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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