1
votes

I have a Winforms app written in C#.

In DataGridView, I have set a column(DataGridViewTextBoxColumn) called 'Name' to ReadOnly = true.

When the user right click on a Cell of the 'Name' column -> Display a form to set a value -> I want the application to know: Cell's value of the 'Name' column has been changed.

I have tried many events but can not do, such as CellEndEdit, CellValueChanged

I'm only interested in catching user changes to data in the 'Plan' column where ReadOnly = true.

Which is the best event to use for this? I attach information as below:

① Image Description

② Source Code

1
I don't really get you, if it's ReadOnly, how can it be user-changed ?Ryan B.
The user changes through form. I've added pictures description and source code. Please confirm! Thank you!MinhKiyo
Compare the value of the textbox after the click on the OK button with the value of the cell.Ryan B.

1 Answers

0
votes

The CellEndEdit and CellValueChanged properties only work when the user changes manually the content of the DataGridView. What you have to do is just to read the value of the TextBox in the Set_Value_Of_Name form and compare it with the value of the DataGridView cell.

Add the following line :

btnOK.Click += (senderq, eq) =>
{
  frmValueOfName.Close();
  result = true;

  //Add this line
  if (txtValue.Text != dataGridView[currentMouseOverCol,currentMouseOverRow].Value.ToString())
  {
       MessageBox.Show("Value has been changed!");
  }
};