This is a migrated thread and some comments may be shown as answers.

Getting at the "old" value in CellEndEdit

1 Answer 1023 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 16 Dec 2017, 06:49 PM

When a user edits a cell and I need to update a row, I need to know the old value that was there before (I cannot get it without the entire data set).

Right now as a hack I'm saving it in CellBeginEdit, but I'm hoping there's a better solution:

 

        string oldValue;
        private void deviceGrid_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {
            if (e.Column.Name == "DeviceName")
            {
                oldValue = e.Row.Cells["DeviceName"].Value.ToString();
            }
        }

        private void deviceGrid_CellEndEdit(object sender, GridViewCellEventArgs e)
        {
            if (e.Column.Name == "DeviceName")
            {
                string newName = e.Value.ToString();

                Device device = Program.SapphireService.GetDeviceXmlByID(oldValue);
                Program.SapphireService.UpdateDevice(device, newName);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Dec 2017, 07:51 AM
Hello Dave,

You can use the RowsChanging event where both values are available:
private void RadGridView1_RowsChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanging)
    {
        Console.WriteLine(e.NewValue);
        Console.WriteLine(e.OldValue);
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or