Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
Restore cell value on BeforeExitEditMode Event
posted

Hi,

I do the validation on BeforeExitEditMode and keep the focus in cell if it the condition is not true. I want to restore the value of the cell if valid criteria is not met. My code is below:-

 

Private Sub UltraGrid1_BeforeExitEditMode(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs) Handles UltraGrid1.BeforeExitEditMode

Dim result As DialogResult

Dim aCell As UltraGridCell

If e.CancellingEditOperation Then Return

'check code column and check if there is some value in it

aCell = UltraGrid1.ActiveCell

If (aCell.Column.Key = "Code") And Not (DBNull.Value.Equals(aCell.Text)) Then

'do validation here

If aCell.Text = "9" Then

If e.ForceExit Then

' If the UltraGrid must exit the edit mode, then cancel the

' cell update so the original value gets restored in the cell.

Me.UltraGrid1.ActiveCell.CancelUpdate()

Return

End If

result = MessageBox.Show("Invalid Value", "Test", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)

If result = Windows.Forms.DialogResult.Yes Then

Me.UltraGrid1.ActiveCell.CancelUpdate() 'here i try to cancel with cell.cancelupdate but it doesn't restore the value

aCell.SelectAll()

CodeIsInValid = True

e.Cancel = True

End If

End If

End If

End Sub

 

Is there any way to achieve this?

Thanks in advance,

Parv

Parents
No Data
Reply
  • 235
    posted

    Try this: to cancel the update.

    Private Sub yourUltraGrid_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles ultraGrid1.BeforeCellUpdate

      ' You may update the if statement to match your logic
        If GetType(e.NewValue) != GetType(int) Then
             e.Cancel = true;
             MsgBox("Only integers are allowed in this field.");
        End If
    End Sub

Children
No Data