Visual Basic.NET - CellValidated cuando cierro formulario

 
Vista:

CellValidated cuando cierro formulario

Publicado por Richard Alexis (10 intervenciones) el 10/08/2021 19:09:35
Buenos días, tengo una serie de instrucciones (que graban datos en una tabla) dentro de un GridView en su evento CellValidated.

El inconveniente que tengo es cuando cierro el formulario se vuelve a llamar al evento CellValidated de mi GridView
y se vuelve a ejecutar las instrucciones y no deseo que se realicen porque sino se realizan insercciones duplicadas en la tabla involucrada.

Por favor su apoyo con esta duda.

Muy agradecido de antemano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

CellValidated cuando cierro formulario

Publicado por Phil Rob (1554 intervenciones) el 10/08/2021 21:51:01
Hola,

Solamente una pregunta : porqué no utilizar otro evento para llenar un DataGrid?

Quizá puedes enviar el código del procedimiento CellVallidaded ?

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

CellValidated cuando cierro formulario

Publicado por Richard Alexis (10 intervenciones) el 10/08/2021 22:06:59
Private Sub dgv4_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv4.CellValidated

Try

If Not dgv4.CurrentCell.ColumnIndex = 5 Then

Exit Sub
End If

If cantidad_recepcionar = 0 And dvguias_transportista_bultos.Table.Rows(dr).IsNull("CANTIDAD_RECEPCIONAR") Then
Exit Sub
End If
If Not dvguias_transportista_bultos.Table.Rows(dr).IsNull("CANTIDAD_RECEPCIONAR") Then
If cantidad_recepcionar = Val(dvguias_transportista_bultos.Table.Rows(dr)("CANTIDAD_RECEPCIONAR")) Then Exit Sub
End If


Dim objGUIA_TRANSPORTISTA_DETALL As New ClsLb.dtoGUIA_TRANSPORTISTA_DETALL
Dim dv As New DataView
objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL = dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("IDGUIA_TRANSPORTISTA_DETALL")

If Not dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index).IsNull("CANTIDAD_RECEPCIONAR") Then
objGUIA_TRANSPORTISTA_DETALL.CANTIDAD_RECEPCIONAR = Val(dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR"))
dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") = Val(dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR"))
If dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") > dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD") Then
MsgBox("La cantidad a recepcionar no puede ser mayor que la de envio", MsgBoxStyle.Information, "Segurdidad del Sistema")
dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") = cantidad_recepcionar
Exit Sub
End If
If dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") < 0 Then
MsgBox("La cantidad a recepcionar no puede ser negativo", MsgBoxStyle.Information, "Segurdidad del Sistema")
dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") = cantidad_recepcionar
Exit Sub
End If
Else
objGUIA_TRANSPORTISTA_DETALL.CANTIDAD_RECEPCIONAR = 0
End If
objGUIA_TRANSPORTISTA_DETALL.IDUNIDAD_AGENCIA = dtoUSUARIOS.m_idciudad
objGUIA_TRANSPORTISTA_DETALL.IDUSUARIO_PERSONAL = dtoUSUARIOS.IdLogin

dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR") = Val(dvguias_transportista_bultos.Table.Rows(dgv4.CurrentRow.Index)("CANTIDAD_RECEPCIONAR"))
'
'Mod.12/10/2009 -->Omendoza - Pasando al datahelper -
'dv = objGUIA_TRANSPORTISTA_DETALL.sp_RECEPCIONAR_BULTOSIII(VOCONTROLUSUARIO)
dv = objGUIA_TRANSPORTISTA_DETALL.sp_RECEPCIONAR_BULTOSIII()

'Dim aaa As Integer = id_guia_transportista

Dim obj_gui_transpor As New INTEGRACION_LN.Cls_Guias_LN
Dim dt_gui_transpor As DataTable
Dim id_age_destino As Integer
dt_gui_transpor = obj_gui_transpor.Retornar_Datos_Guia_Transportista(id_guia_transportista)
id_age_destino = dt_gui_transpor.Rows(0).Item(0).ToString
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim dvListar_ageVirtuales As New DataView
dvListar_ageVirtuales = obj_gui_transpor.Listar_agencias_virtuales()
'agencias virtuales
For i As Integer = 0 To dvListar_ageVirtuales.Table.Rows.Count - 1
Dim idagencia_virtual As Integer = dvListar_ageVirtuales.Table.Rows(i)("idagencias")
If id_age_destino = idagencia_virtual Then
Dim obj_grt_det As New INTEGRACION_LN.Cls_Guias_LN
obj_grt_det.Actualizar_Doc_GRT(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL)
End If
Next

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'agencias virtuales
'If id_age_destino = 204 Then
' 'actualizar la guia o factura a 20 llegada
' Dim obj_grt_det As New INTEGRACION_LN.Cls_Guias_LN

' obj_grt_det.Actualizar_Doc_GRT(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL)

'End If

If dv.Table.Rows(0)("retor_es_recepcionado") = 0 Then
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("es_recepcionado") = 0
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("Es_Recepcionado_decrip") = "DESP."

Try
ObjWebService.fnWebServiceLlegada(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL.ToString())
Catch ex As Exception
End Try

ElseIf dv.Table.Rows(0)("retor_es_recepcionado") = 1 Then
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("es_recepcionado") = 1
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("Es_Recepcionado_decrip") = "RECEP."

Try
ObjWebService.fnWebServiceLlegada(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL.ToString())
Catch ex As Exception
End Try


ElseIf dv.Table.Rows(0)("retor_es_recepcionado") = 2 Then
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("es_recepcionado") = 2
dvguias_transportista.Table.Rows(DGV3.CurrentRow.Index)("Es_Recepcionado_decrip") = "RECEP. PARCIAL"


Try
ObjWebService.fnWebServiceLlegada(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL.ToString())
Catch ex As Exception
End Try


Else

MsgBox(dv.Table.Rows(0)(2), MsgBoxStyle.Information, "Seguridad del Sistema...")


dvguias_transportista_bultos.Table.Rows(dr)("CANTIDAD_RECEPCIONAR") = cantidad_recepcionar

End If

Recepcionar_valijas(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL)
'nuevo itinerario pasajes
'********************************************************************************************
Dim obj_RecepcionarItinerario As New Cls_Ventas_LN
obj_RecepcionarItinerario.RecepcionarItinerarioDocumentos(objGUIA_TRANSPORTISTA_DETALL.IDGUIA_TRANSPORTISTA_DETALL, dvguias_transportista_bultos.Table.Rows(dr)("CANTIDAD_RECEPCIONAR"))
'********************************************************************************************

Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Information, "Seguridad del Sistema...")
End Try
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

CellValidated cuando cierro formulario

Publicado por Phil Rob (1554 intervenciones) el 10/08/2021 23:25:51
Hola,

Quizá puede utilizar el evento CellValueChanged a lugar de CellValidaded.

1
2
3
4
5
6
7
8
9
10
11
Private Sub dgv4_CellValueChanged
 (ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv4. CellValueChanged
 
Try
 
If Not dgv4.e.ColumnIndex = 5 Then
Exit Sub
End If
 
If cantidad_recepcionar = 0  … … …
' ... ... ... 

Si no es posible de hacer esto, te propongo de desactivar el evento CellValidaded ante la cerrada del Form. Pienso que el código siguiente debería evitar la ejecución del CellValidaded al momento de la cerrada del Form.

1
2
3
4
Private Sub ElFormDelProblema_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        RemoveHandler dgv4.CellValidaded, AddressOf dgv4.CellValidaded
‘ … … …
End Sub

Espero que este te ayudará …
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

CellValidated cuando cierro formulario

Publicado por Phil Rob (1554 intervenciones) el 11/08/2021 08:10:44
Continuacion ...

Perdón me, me he equivocado en la escritura del código que te enviar : AdressOf debe es continuar por el nombre del procedimiento (dgv4_CellValidaded) y no cual de Handler (dgv4.CellValidaded).

El codigo correcto :

1
2
3
4
Private Sub ElFormDelProblema_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        RemoveHandler dgv4.CellValidaded, AddressOf dgv4_CellValidaded
‘ … … …
End Sub

Que tenga un buen día ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

CellValidated cuando cierro formulario

Publicado por Richard Alexis (10 intervenciones) el 11/08/2021 15:34:26
Hola estimado, sigue igual...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

CellValidated cuando cierro formulario

Publicado por Phil Rob (1554 intervenciones) el 11/08/2021 16:16:18
Mismo con el RemoveHandler en el procedimiento FormClosing del Form ?

En este caso, tiene que ejecutar paso a paso (<F11>) para ver cuando viene el tratamiento que no quieras.

Ya, poner un MessageBox.Show a la primera línea del procedimiento dgv4_CellValidaded te permite de ver si pasa a este lugar cuando el Form cierra.
También veras cada vez que pasa y que este es como que viene el malo tratamiento.

Voy testar la ejecución de evento CellValidaded et te diré.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

CellValidated cuando cierro formulario

Publicado por Phil Rob (1554 intervenciones) el 11/08/2021 17:36:23
Tiene razon, el evento CellValidaded viene ante otros eventos y no veo donde poner el RemoveHandler ...

El evento CellValidaded viene cada vez que sales de una celda. Tambien es el caso para el evento CellLeave. Pero este ultimo no se actívate cuando el Form cerra. Quizá debes intentar de reemplazar el evento CellValidaded por CellLeave.

...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar