locked
DataGridView Undo/Redo Copy/Cut/Paste RRS feed

  • Question

  • Hi,

    I am planning to do these features on a win form application. If remember correctly the redo and undo both are already implemented by the DataGridControl, and apparently there is no need to code them from scratch. I was wondering if anyone is aware of good resources/references for this task.

    Regarrds,
    Reza Bemanian
    Saturday, July 14, 2007 4:36 AM

Answers

  • Yes, using the DataTable.GetChanges() method you can get all the changes that made to the DataTable which is the DataSource of the DataGridView, the DataTable.Rejectchanges() method can roll back all changes that have been made to the table since it was loaded, or the last time AcceptChanges was called. A simple code snippet:

    Code Snippet

    private void button1_Click(object sender, EventArgs e)

            {

                //undo all the operations

                DataTable dt = this.dataGridView1.DataSource as DataTable;

                dt.RejectChanges();

            }

     

    This project shows a more powerful solution on this: DataTable Transaction Logger
    Monday, July 16, 2007 4:59 AM

All replies

  • This issue has been discussed in this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1180600&SiteID=1,
    Sunday, July 15, 2007 5:34 PM
  • Hi,

    My question was referring to the changes made to the DGV as a whole, and not the text content within an individual cell. It seems as one way to do this is by examining the row state to reverse the change, if the state indicates it. The problem is that you could only keep track of one change to a single row, and I was wondering if there exist any other way to record the changes made to a DGV or a dataset? Obviously, what is trying to be avoided is to code this manually.

    Regards,
    Reza Bemanian
    Monday, July 16, 2007 12:50 AM
  • Yes, using the DataTable.GetChanges() method you can get all the changes that made to the DataTable which is the DataSource of the DataGridView, the DataTable.Rejectchanges() method can roll back all changes that have been made to the table since it was loaded, or the last time AcceptChanges was called. A simple code snippet:

    Code Snippet

    private void button1_Click(object sender, EventArgs e)

            {

                //undo all the operations

                DataTable dt = this.dataGridView1.DataSource as DataTable;

                dt.RejectChanges();

            }

     

    This project shows a more powerful solution on this: DataTable Transaction Logger
    Monday, July 16, 2007 4:59 AM
  • Hi,

    Thanks so much for the immediate reply. I have to try this out, but it seems that  both the list of changes and the ability to reject each is provided by the routines you referenced. I had the article in the code project which you provided its link reviewed a bit earlier, as interesting as the article was it did not fully applied to my project. Hopefully after coding this part I will be able to inform the forum of the details. Thanks again for the information.

    Regards,
    A. Reza Bemanian
    Tuesday, July 17, 2007 2:08 AM
  • Hi,

    Getting back to this seems GetChnages and RejectChanges methods roll-back or accept the changes in their entirety, Or, provide a single stage redo/undo process. So if the intent is to keep track of the changes and step through them step by step in either direction, these functions are not the best of the choices. Are there any other support in the framework for such a task?

     

    Regards,

    Reza Bemanian

    Tuesday, August 21, 2007 3:00 AM
  • Hi ! Instead of undoing all operations , is there any way to undo it one by one ?
    Wednesday, April 16, 2014 3:46 AM