
Restar en data grid view
Publicado por anonymous (29 intervenciones) el 22/01/2020 11:12:59
Buen día. tengo un inconveniente en un data grid view. en el mismo tengo distintos campos que los que interesan son importe y tipo de pago como se ve en la imagen.

yo necesito que si un numero de cuenta tiene tipo de pago 2 y también tipo de pago 1 que se resten los importes seria así (importe de tipo de pago 2 - importe de tipo de pago 1). yo pude realizar algo así sin embargo me lo resta mas de una vez, podrían revisar mi codigo? ojala entiendan, trate de ser lo mas claro posible.

yo necesito que si un numero de cuenta tiene tipo de pago 2 y también tipo de pago 1 que se resten los importes seria así (importe de tipo de pago 2 - importe de tipo de pago 1). yo pude realizar algo así sin embargo me lo resta mas de una vez, podrían revisar mi codigo? ojala entiendan, trate de ser lo mas claro posible.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'AQUI SE REALIZA LA CUENTA DEL IMPORTE TOTAL CUANDO EL TIPO DE PAGO ES 2 MENOS EL IMPORTE DE TIPO DE PAGO 1
Private Sub AjustarImporte2(ByVal cuentacuil As String)
Dim CuentaClientABuscar As String
Dim IndiceColumnaCuenta As Integer = 2
Dim IndiceColumnaTipoPago As Integer = 4 ' este variable no es utilizado en este ejemplo
Dim IndiceColumnaImporte As Integer = 5
Dim resul As Double
Dim Importe1 As Double
Dim Importe2 As Double
CuentaClientABuscar = cuentacuil
For L As Integer = 0 To DataGridView22.Rows.Count - 2 ' Escribir -1 si no existe una ultima linea vacia
If DataGridView22.Item(IndiceColumnaCuenta, L).Value = CuentaClientABuscar Then
Importe2 = CType(DataGridView22.Item(IndiceColumnaImporte, L).Value, Double)
If CType(DataGridView22.Item(IndiceColumnaTipoPago, L + 1).Value, Integer) = 1 Then
Importe1 = CType(DataGridView22.Item(IndiceColumnaImporte, L + 1).Value, Double)
resul = Importe2 - Importe1
DataGridView22.Item(IndiceColumnaImporte, L).Value = String.Format("{0:##0.00}", resul / 100).Replace(",", ".")
End If
Exit For
End If
Next
End Sub
'este es el codigo que llama a esa funcion
For Each item As DataGridViewRow In DataGridView22.Rows
If (item.Cells("CUENTAA").Value > 1 And item.Cells("TIPODEPAGO").Value = 1) - 1 Then
cuentacuil = item.Cells("CUENTAA").Value
AjustarImporte2(cuentacuil)
Else
SOLO_VALOR = 45
End If
Next
Valora esta pregunta


0