Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView Event to Catch When Cell Value Has Been Changed by User

Tags:

I have a Winforms app written in C#.

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

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.

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?

like image 471
PJW Avatar asked Oct 23 '13 09:10

PJW


1 Answers

CellValueChanged is what you need:

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

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   } } 
like image 61
King King Avatar answered Oct 07 '22 01:10

King King