Home Forums WinForms controls Xceed Grid for WinForms Insertionrow cancel

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17045 |

    If I want to cancel my insertionrow edit (maybe the db rejected the query because of primary key etc), can I cancel and keep the data that the user has already entered into the various cells of the insertionrow?

    vb.net please

    Thanks in advance.

    Imported from legacy forums. Posted by troy@querytool.com (had 2161 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    When I tryed this, after restoring the values (which worked) when I clicked on a different cell in the insertion row, the cell value became empty – and looks like the cells value is Nothing.

    Any ideas?

    Imported from legacy forums. Posted by troy@querytool.com (had 1721 views)

    User (Old forums)
    Member
    Post count: 23064

    This was only a basic implementation, and you need to increment on it, so it works as you need in all scenarios.  For example, once the InsertionRow enters edition, the IdleValue of insertion cells are discarded, and the underlying DataRow  is created, so you need to set the Value property on each cell.  To do this, you need to handle the EditBegun event on the InsertionRow.

    e.g.:

        void insertionRow1_EditBegun( object sender, EventArgs e )
        {
          InsertionRow insertionRow = sender as InsertionRow;
          if( insertionRow != null )
          {
            foreach( InsertionCell cell in insertionRow.Cells )
            {
              if( cell.IdleValue != null )
              {
                cell.Value = cell.IdleValue;
              }
            }
          }
        }

     

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.