I have an UltraWinGrid
in one of my forms that is used for the user to enter VAT rates into. There are 3 columns:
I need to validate the grid so that if there is a value entered in the "Date From" cell of a row, the user can only enter a minimum value of the "Date From" value + 1 day.
In which method would this go? And how do I do it?
I have tried doing
Private Sub ugVatRates_BeforeCellActivate(sender As Object, e As CancelableCellEventArgs) Handles ugVatRates.BeforeCellActivate
Dim dateFrom As Date
If IsDBNull(e.Cell.Row.Cells("DateFrom").Value) = False OrElse e.Cell.Row.Cells("DateFrom").Value <> Nothing Then
dateFrom = e.Cell.Row.Cells("DateFrom").Value
e.Cell.Row.Cells("DateTo").MinValue = dateFrom.AddDays(1)
End If
End Sub
However, MinValue
is not a valid property here - Any advice?
Yes, MinValue and MaxValue are only exposed by UltraGridColumn. However, this will not work in your case. What you can do is handle BeforeCellUpdate event. In this event check if the cell user tries to update is DateTo cell as well as in DateFrom has value. If so you may suppress accepting of the new value by setting e.Cancel to true like this:
Private Sub ugVatRates_BeforeCellActivate(sender As Object, e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles ugVatRates.BeforeCellUpdate
If e.Cell.Column.Header.Caption = "DateTo" Then
Dim dateFrom As Date
Dim dateTo As Date
If IsDBNull(e.Cell.Row.Cells("DateFrom").Value) = False OrElse e.Cell.Row.Cells("DateFrom").Value <> Nothing Then
dateFrom = e.Cell.Row.Cells("DateFrom").Value
dateTo = Date.Parse(e.Cell.Row.Cells("DateTo").Text)
If dateTo < dateFrom.AddDays(1) Then
' Suppress accepting of new value
e.Cancel = True
End If
End If
End If
End Sub
When the user enters invalid date you may show a message box to inform him, or use UltraGrid's Data Validation.