0

How do I have multiple undo & redo function with my following code ?

private void btn_Undo_Click(object sender, EventArgs e) //To Undo previous searched record
    {
        if (_dataSet != null && _dataSet.Tables.Count > 0 && _lastDtTable2 != null)
        {
            _dataSet.Tables.Clear();
            _dataSet.Tables.Add(_lastDtTable2);
            dataGridView1.DataSource = _dataSet.Tables[0];
        }
    }
    private void btn_Redo_Click_2(object sender, EventArgs e)
    {
        if (_dataSet != null && _dataSet.Tables.Count > 0 && _lastDtTable2 != null)
        {
            _dataSet.Tables.Add();
            dataGridView1.DataSource = _dataSet.Tables[0];
        }

I only can undo once

1 Answers1

0

To maintain multpile undo's you will need to use a structure(e.g. a Stack is a good one), and keep the users history.

Each action is "pushed" into the stack.

Each time he presses "back", you simple "pop" the old state and do what you want with it.

Amir Popovich
  • 29,350
  • 9
  • 53
  • 99