03-06-14, 09:59 AM
كملت على مثال الاخ vb.net واضفت 2 من stack واحد لل undo والثاني redo:-
جرب الان وشوف :-
جرب الان وشوف :-
PHP كود :
#Region " DataGridViewStacks"
Private dataGridViewRedoStack As New Stack(Of Info)()
Private dataGridViewUndoStack As New Stack(Of Info)()
Public Structure Info
' عدد الأسطر
Public rows As Integer
' رقم السطر
Public row As Integer
' رقم العمود
Public col As Integer
' قيمة الخلية
Public val As Object
End Structure
Private Sub dataGridView1_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs)
Handles dataGridView1.CellBeginEdit
Dim o As New Info()
o.rows = dataGridView1.Rows.Count
o.row = dataGridView1.CurrentCell.RowIndex
o.col = dataGridView1.CurrentCell.ColumnIndex
o.val = dataGridView1.CurrentCell.Value
dataGridViewUndoStack.Push(o)
End Sub
Private Sub DataGridViewDoUndo()
If dataGridViewUndoStack.Count > 0 Then
Dim newInfo As New Info()
newInfo.col = dataGridViewUndoStack.First().col
newInfo.row = dataGridViewUndoStack.First().row
newInfo.rows = dataGridViewUndoStack.First().rows
newInfo.val = dataGridView1.Rows(newInfo.row).Cells(newInfo.col).Value
dataGridViewRedoStack.Push(newInfo)
Dim o As New Info()
o = dataGridViewUndoStack.Pop()
Me.dataGridView1.Rows(o.row).Cells(o.col).Value = o.val
Me.dataGridView1.CurrentCell = dataGridView1.Rows(o.row).Cells(o.col)
While dataGridView1.Rows.Count > o.rows
dataGridView1.Rows.RemoveAt( _
If(dataGridView1.AllowUserToAddRows, dataGridView1.Rows.Count - 2, dataGridView1.Rows.Count - 1))
End While
End If
End Sub
Private Sub DataGridViewDoRedo()
If dataGridViewRedoStack.Count > 0 Then
Dim newInfo As New Info()
newInfo.col = dataGridViewRedoStack.First().col
newInfo.row = dataGridViewRedoStack.First().row
newInfo.rows = dataGridViewRedoStack.First().rows
newInfo.val = ""
dataGridViewUndoStack.Push(newInfo)
Dim o As New Info()
o = dataGridViewRedoStack.Pop()
While dataGridView1.Rows.Count < o.rows
dataGridView1.NotifyCurrentCellDirty(True)
dataGridView1.Rows.Insert(dataGridView1.Rows.Count - 1, 1)
End While
Me.dataGridView1.Rows(o.row).Cells(o.col).Value = o.val
Me.dataGridView1.CurrentCell = dataGridView1.Rows(o.row).Cells(o.col)
End If
End Sub
#End Region
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
DataGridViewDoUndo()
End Sub
Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
DataGridViewDoRedo()
End Sub

