View Single Post
  #2 (permalink)  
Old 05-13-2008, 05:48 AM
Erel's Avatar
Erel Erel is offline
Administrator
 
Join Date: Apr 2007
Posts: 2,964
Default

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
Reply With Quote