Necesito tutorial para para agregar, eliminar y modificar datos en el DataGrid en Maestro/Detalles

Hola, mi pregunta es si tienes algún tutorial o en lo posible algún
código de cómo funciona el DataGrid en el Maestro/Detalles, lo que pasa es
que tengo inconvenientes al agregar, eliminar y modificar en el DataGrid
(Ej. Detalles de Factura(Item, Detalle, Vr Unit, Vr Total). Te agradecería si me das una manito o
donde puedo buscar bastante documentación y código al respecto.
Gracias
Edison Pérez
Respuesta
1
Suponiendo que tiene el maestro en una matriz txtfields de controles text vos y un grid como detalle todo el código de ejemplo seria
Option Explicit
Private Sub Form_Load()
Set grdDataGrid.DataSource = datPrimaryRS.Recordset("ChildCMD").UnderlyingValue
End Sub
Private Sub Form_Resize()
On Error Resume Next
'Esto cambiará el tamaño de la cuadrícula al cambiar el tamaño del formulario
grdDataGrid.Width = Me.ScaleWidth
grdDataGrid.Height = Me.ScaleHeight - grdDataGrid.Top - datPrimaryRS.Height - 30 - picButtons.Height
End Sub
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
End Sub
Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
'Aquí es donde puede colocar el código de control de errores
'Si desea pasar por alto los errores, marque como comentario la siguiente línea
'Si desea detectarlos, agregue código aquí para controlarlos
MsgBox "Data error event hit err:" & Description
End Sub
Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'Esto mostrará la posición de registro actual para este Recordset
datPrimaryRS.Caption = "Record: " & CStr(datPrimaryRS.Recordset.AbsolutePosition)
End Sub
Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'Aquí se coloca el código de validación
'Se llama a este evento cuando ocurre la siguiente acción
Dim bCancel As Boolean
Select Case adReason
Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select
If bCancel Then adStatus = adStatusCancel
End Sub
Private Sub cmdAdd_Click()
On Error GoTo AddErr
datPrimaryRS.Recordset.AddNew
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
With datPrimaryRS.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
Exit Sub
DeleteErr:
MsgBox Err.Description
End Sub
Private Sub cmdRefresh_Click()
'Esto sólo es necesario en aplicaciones multiusuario
On Error GoTo RefreshErr
datPrimaryRS.Refresh
Set grdDataGrid.DataSource = datPrimaryRS.Recordset("ChildCMD").UnderlyingValue
Exit Sub
RefreshErr:
MsgBox Err.Description
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
datPrimaryRS.Recordset.UpdateBatch adAffectAll
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas