如何在DataGridView行之前/之后保存/测试 [英] How to save/test before/after DataGridView Row

查看:63
本文介绍了如何在DataGridView行之前/之后保存/测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户获得焦点之前将DataGridView中的行与用户失去焦点之后的行进行比较.我正在执行此操作以查看行中是否有任何更改.

这是我尝试执行的操作:
(注意:dgvPhysCME是DataGridView控件的名称.)

在表单类中,我定义了以下临时行...

I am trying to compare a row in a DataGridView before the user gets focus to the row after the user loses focus. I''m doing this to see if anything in the row was changed.

Here''s how I am trying to do this:
(Note: dgvPhysCME is the name of the DataGridView control.)

In the Form Class, I have the following temporary rows defined...

Dim rwBefRow As New DataGridViewRow  'Row when focus moves to row
Dim rwAftRow As New DataGridViewRow  'Row when focus leaves row


然后在RowEnter事件中,我有...


Then in the RowEnter event, I have...

rwBefRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)


然后在RowLeave事件中,我有...


Then in the RowLeave event, I have...

rwAftRow = CType(dgvPhysCME.Rows(e.RowIndex), DataGridViewRow)


当我在调试中运行此命令时,可以在RowEnter事件中列出"before"值.但是,一旦进入RowLeave事件,rwBefRow中的"before"值已更新为"current"值,因此rwBefRow中的所有值都与rwAftRow相同. >
我究竟做错了什么?

谢谢,Eddie


When I run this in debug, I can list the "before" values in the RowEnter event just fine. However, once I get into the RowLeave event the "before" values in rwBefRow have been updated to the "current" values so all the values in the rwBefRow are the same as the rwAftRow.

What am I doing wrong?

Thanks, Eddie

推荐答案



基本上,您想要的是在获得焦点之前和离开焦点之后比较DataGridViewRow中的值.

DataGridViewRow是引用类型的数据类型,因此当您更改行中的值时,它将修改u存储在rwBefRow中的实例.

在这里,我想您需要做的是代替比较完整的行,而应该尝试比较该特定行中的值.

我可以想到几种实现方式.
1.将行的值存储在焦点之前的某个位置,在离开事件中,将行中的新值与存储在某处的旧值进行比较.

2.在离开事件时,不存储值,而是将行中的值与要绑定datagridview的数据源中的值进行比较.

希望对您有帮助.

谢谢和问候,
Chetan Ranpariya
Hi,

Basically what you want is to compare the values in the DataGridViewRow before getting focus and after leaving focus.

DataGridViewRow is a reference type datatype hence when you change value in the row it will modify the instance which u stored in rwBefRow.

Here I guess what you need to do is instead of comparing the full rows you should try to compare the values in that particular row.

I can think of couple of way to implement.
1. Store values of the row somewhere before focus, and in leave event you compare new values in the row to the old values which you stored somewhere.

2. Instead of storing the values, on leave event you compare the values in the row with the values in the datasource to which you are binding your datagridview.

I hope this will help you.

Thanks and regards,
Chetan Ranpariya


谢谢.

那行得通.

埃迪
Thanks.

That worked.

Eddie


这篇关于如何在DataGridView行之前/之后保存/测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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