Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor whenever a cell value is changed in DataGridView?

This is a WinForms C# question.

I have a customized DataGridView control inherited from the standard DataGridView class. I want to monitor the case whenever a cell is added to the grid, a cell value is changed in the grid. I have no idea how to do this.

The DataBindingCompleted event is helpless in cell/row/column level. The CellValueChanged event is confusing itself since it is only fired when user modifies a value from UI and is helpless if the value is updated from underlying data source. What is the proper event to listen to?

I know DataGridViewCell class has a ValueChanging event. But in the customized DataGridView, how can I hook my event listener to every cell?

Thanks for the help.

like image 605
Steve Avatar asked Aug 27 '10 02:08

Steve


1 Answers

1、You may inherit DataGridView when customized DataGridView.If inherit UserControl to customize DataGridView,you can not directly get CellValueChanged event when generate customized DataGridView in other project or application.

2、To do something in the CellValueChanged.

3、Inherit DataGridView implement.

(1) Create UserControl.Name is DataGridViewEx.

(2) Modify inherit. public partial class DataGridViewEx : UserControl==>public partial class DataGridViewEx :DataGridView

(3)Open DataGridViewEx.Designer.cs and shield //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;.The sentence is in the method InitializeComponent().

like image 114
user2492798 Avatar answered Oct 18 '22 11:10

user2492798