1

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

MinhKiyo
  • 191
  • 3
  • 15

1 Answers1

0

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!");
  }
};
Ryan B.
  • 1,270
  • 10
  • 24
  • In the main form, what does the event use? – MinhKiyo Aug 21 '16 at 22:24
  • Thank you! I'll try – MinhKiyo Aug 21 '16 at 22:30
  • Ryan B : It has run well! Thank you! Besides I have problems like the article below, do you know? Please help me! Thanks! [http://stackoverflow.com/questions/38977969/c-sharp-how-to-filter-list-data-into-datagridview-using-datetimepicker] – MinhKiyo Aug 22 '16 at 06:14