用户更改单元格值时要捕获的DataGridView事件 [英] DataGridView Event to Catch When Cell Value Has Been Changed by User

查看:74
本文介绍了用户更改单元格值时要捕获的DataGridView事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的Winforms应用。

I have a Winforms app written in C#.

在我的一个DataGridViews中,我将除 Reference之外的所有列都设置为ReadOnly = true;

In one of my DataGridViews I have set all columns except one called 'Reference' to ReadOnly = true;

我希望应用程序知道用户何时更改了参考列中的任何内容,但是到目前为止,我尝试过的所有事件都比用户更改时发生的事件多得多进行了更改。例如,CurrentCellChanged在最初呈现DataGridView时触发,并且每次用户在行中沿行等单击或制表符时都会触发。

I want the application to know when a User has changed anything in the 'Reference' column, but all the events I have tried so far fire a lot more than when a user has made changes. For example CurrentCellChanged fires when the DataGridView is initially rendered and everytime the user simply clicks or tabs along the rows etc.

我只对捕获用户对数据的更改感兴趣引用列是只读列,其中ReadOnly = false;

I'm only interested in catching user changes to data in the 'Reference' column which is the ONLY column where ReadOnly = false;

哪个是为此使用的最佳事件?

Which is the best event to use for this?

推荐答案

CellValueChanged 是您所需要的:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e){
  if(dataGridView1.Columns[e.ColumnIndex].Name == "Reference"){
    //your code goes here
  }
}

我认为事件 CellEndEdit 也适合您的需求:

I think the event CellEndEdit is also suitable for your want:

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e){
  if(dataGridView1.Columns[e.ColumnIndex].Name == "Reference"){
    //your code goes here
  }
}

这篇关于用户更改单元格值时要捕获的DataGridView事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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