What is the best way to detect a change of content in datagridview VS 2008?

1

I have a datagridview, which has columns that I can edit (with the EditMode property: EditOnEnter). I have this grid only to show data, because the values (without formatting, for calculations) I have in an array.

I need to capture the data that changed in the grid, to also modify the array. (And perform the calculations depend on the cell that changed). For this, what is closest to what I need is the CurrentCellDirtyStateChanged event. The problem is that I also get up the event as soon as I change the first number of the cell, otherwise it works well. But I have tried several things without success. Someone who knows how to do a workaround for this?

    
asked by Esteban Cantillano 01.06.2016 в 19:00
source

2 answers

1

Use the CellEndEdit event

DataGridView.CellEndEdit (Event)

with this event you will have the notification when the cell stops editing.

Of course this will be launched whether or not there has been a change in the cell, but you could use it in conjunction with the CellBeginEdit

DataGridView.CellBeginEdit (Event )

saving in a variable the original value for after compare it with the entered one, if they are equal then no change was made

private string temp = "";

public DataGridView1_CellBeginEdit(...)
{
    temp = DataGridView1.CurrentCell.Value.ToString();
}

public DataGridView1_CellBEndEdit(...)
{
    string cellVaue = DataGridView1.CurrentCell.Value.ToString();
    if( cellVaue == temp)
    {
        //no se realizo ningun cambio
    }

}
    
answered by 01.06.2016 / 19:54
source
0

The CurrentCellDirtyStateChanged event is precisely for that: it occurs every time the value that is being edited changes, but in reality the value of the cell has not yet been established.

To control when you change the value of a cell you should use the CellValueChanged event.

    
answered by 01.06.2016 в 19:48