Search code examples
c#winformseventsdatagridviewcells

How to check if the value of a DataGridViewCalendarColumn has been changed?


I have a data grid with a calendar column. What I want to do is an event (not sure which one is suitable), and this is what should happen:

  1. There should be a check to see if one of the row's dates were changed;
  2. If the value of one row has been changed (specifically the date column - which is also the only editable column), another method will execute (let's call it Update()) - I already have the method figured out. I just don't know how to do the whole check to see if a value has been changed.

CellValueChanged doesn't work as it is triggered if anything changed on the grid, such as loading the data etc. Is there something else I can use?

Let me know if I need to add more info, I'm not quite sure how to do this.


Solution

  •     private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
            if (column.Name == "dateColumn")
            {
                UpdateStuff();
            }
        }
    
        private void UpdateStuff()
        {
            object myDate = dataGridView1.CurrentCell.Value;
        }