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?
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 } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With