Home Forums WinForms controls Xceed Grid for WinForms Insertionrow cancel Reply To: Insertionrow cancel

User (Old forums)
Member
Post count: 23064

You can use the LeavingEdit and EditCanceled events to save and then restore the values to the InsertionRow cells.  Here is a basic implementation :

 Private values As Dictionary(Of String, Object)

 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

   For Each insertionCell As InsertionCell In insertionRow1.Cells
     AddHandler insertionCell.LeavingEdit, AddressOf insertionCell_LeavingEdit
   Next insertionCell

   AddHandler insertionRow1.EditCanceled, AddressOf insertionRow1_EditCanceled

   values = New Dictionary(Of String, Object)(0)
 End Sub

 Private Sub insertionCell_LeavingEdit(ByVal sender As Object, ByVal e As LeavingEditEventArgs)

   Dim cell As InsertionCell = TryCast(sender, InsertionCell)

   If cell IsNot Nothing Then
     values.Add(cell.FieldName, e.NewValue)
   End If
 End Sub

 Private Sub insertionRow1_EditCanceled(ByVal sender As Object, ByVal e As EventArgs)

   Dim insertionRow As InsertionRow = TryCast(sender, InsertionRow)
   Dim value As Object

   If insertionRow IsNot Nothing Then
     For Each fieldName As String In values.Keys
       If values.TryGetValue(fieldName, value) Then
         CType(insertionRow.Cells(fieldName), InsertionCell).IdleValue = value
       End If
     Next fieldName
   End If

   values.Clear()
 End Sub

 

Imported from legacy forums. Posted by André (had 438 views)