Multiple Undo/Redo

Discussion in 'Questions (Windows Mobile)' started by Rioven, May 12, 2008.

  1. Rioven

    Rioven Active Member Licensed User

    What are nice ways to implement multiple undo and redo on applications like
    text editor or table entries?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The following code implements multiple Undo in a table.
    This code will not work if the value of a cell contains a comma.
    You can change it to work with some other character like tilde (~) instead.
    alStack is an ArrayList.
    Code:
    Sub Globals
        
    'Declare the global variables here.
        Dim Type(Column,Row,Value) UndoItem
    End Sub

    Sub App_Start
        Form1.Show
        FillTable
    End Sub

    Sub FillTable
        Table1.AddCol(cString,
    "Col 1",50)
        Table1.AddCol(cString,
    "Col 2",50)
        Table1.AddCol(cString,
    "Col 3",50)
        
    For i = 1 To 10
            Table1.AddRow(i,i,i)
        
    Next
    End Sub

    Sub AddItem (column,row,oldValue)
        alStack.Insert(
    0,column & "," & row & "," & oldValue)
    End Sub

    Sub UndoLast
        
    If alStack.Count = 0 Then Return 'No items
        UndoItem() = StrSplit(alStack.Item(0),",")
        alStack.RemoveAt(
    0)
        Table1.Cell(UndoItem.Column,UndoItem.Row) = UndoItem.Value
    End Sub

    Sub btnChange_Click
        col = Table1.SelectedCol
        row = Table1.SelectedRow
        AddItem(col,row,Table1.Cell(col,row)) 
    'Save the previous value
        Table1.Cell(col,row) = txtChange.Text
    End Sub
    Sub btnUndo_Click
        UndoLast
    End Sub
     
  3. Rioven

    Rioven Active Member Licensed User

    Hi Erel, Thanks for this useful sample code for table.:)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice