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
205
Best way to validate data in an UltraWinGrid
posted

When I use the DataGridView Windows Forms control, there is a CellValidating event.  This gets called when the cell loses focus.  In addition, when I click the Save ToolStripButton on my form, since this doesn't cause a transfer of focus, I call the Form.ValidateChildren() method.  This also causes the CellValidating event to fire.  If the data is invalid, I can abort the save operation.  Something like this:

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

  If Me.ValidateChildren()

    SaveDataToDatabase()

  End If

End Sub

Private Sub DataGridView_CellValidating(ByVal sender As Object, ByVal e As CellValidatingEventArgs)

  If (cell value is not valid)

    e.Cancel = true

  End If

End Sub

However, I cannot find an equivalent event for the UltraWinGrid.  I've tried making use of the BeforeCellUpdate and BeforeRowUpdate events, as well as the BeforeExitEditMode event.  There seems to be no easy way to do this if the focus of the cell is not being lost.

Given that I am using the UltraWinGrid, and given that the save operation is initiated by clicking on a ToolStripButton, what is the best way to validate data in an UltraWinGrid and prevent the save operation from taking place?  Obviously, I would also like to deliver feedback to the user that there is a validation problem.

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    What you are looking for is the grid's UpdateData method. This forces the grid to commit any pending changes, as though the grid lost focus.

    You may also want to use the grid's PerformAction method can perform the ExitEditMode action before you call UpdateData to make sure that the cell can exit edit mode safely.

Children
No Data