Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataGrid Usage
Message
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00417985
Message ID:
00418200
Vues:
48
It is possible but extremely annoying to get it to work without crashing your application here is some code that might get you started.
'`'`'`'`'`'
'frmBudget'
'`'`'`'`'`'
Option Explicit

Private Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
   If DataGrid1.Columns(ColIndex).Value = "" Then
      MsgBox DataGrid1.Columns(ColIndex).Caption + " must contain a value"
      Cancel = True
   Else
      If (ColIndex = 1 Or ColIndex = 2) And Not IsDate(DataGrid1.Columns(ColIndex).Value) Then
         MsgBox DataGrid1.Columns(ColIndex).Caption + " must contain a valid date"
         Cancel = True
      ElseIf (ColIndex = 3) And Not IsNumeric(DataGrid1.Columns(ColIndex).Value) Then
         MsgBox DataGrid1.Columns(ColIndex).Caption + " must contain a numeric value"
         Cancel = True
      ElseIf (ColIndex = 3) And DataGrid1.Columns(ColIndex).Value <= 0 Then
         'Do not save the record if no value was entered for the amount
         Cancel = True
      End If
   End If
End Sub

Private Sub DataGrid1_BeforeUpdate(Cancel As Integer)
   If DataGrid1.AddNewMode = dbgAddNewPending Then
      If DataGrid1.Columns(1) = "" Or _
         DataGrid1.Columns(2) = "" Or _
         DataGrid1.Columns(3) = "" Then
            MsgBox "All values must be entered" + vbCr + "Press [ESC] to cancel Addition of record"
            Cancel = True
      End If
      If Not IsNull(DataGrid1.Columns(3)) Then
         If IsNumeric(DataGrid1.Columns(3)) Then
            If DataGrid1.Columns(3) <= 0 Then
               Cancel = True
            End If
         End If
      End If
   End If
End Sub

Private Sub DataGrid1_Error(ByVal DataError As Integer, Response As Integer)
   If DataError = 7011 Then
      Debug.Print "DataGrid1_Error -> " + Str(DataError) + ": Not an error just suppress action cancelled msgbox"
      Response = 0
      DataGrid1.SetFocus
   Else
      Debug.Print "DataGrid1_Error -> " + Str(DataError) + ": " + DataGrid1.ErrorText
      Response = 1
   End If
End Sub

Private Sub DataGrid1_OnAddNew()
   DataGrid1.Columns(1).Value = FormatDateTime(Str(Year(Date)) + "/3/31", vbShortDate)
   DataGrid1.Columns(2).Value = FormatDateTime(Str(Year(Date) + 1) + "/3/31", vbShortDate)
End Sub
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform