Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/02/2016, 15:14
EDUARDOELNOVATO
 
Fecha de Ingreso: febrero-2016
Ubicación: MEXICO
Mensajes: 1
Antigüedad: 8 años, 2 meses
Puntos: 0
Contar filas que cumplen una condicion en datagridview

BUEN DIA POR MÁS QUE BUSQUÉ NO ENCUENTRO TEMAS CON CONDICIONES, LES EXPLICO:

TENGO UN DATAGRIDVIEW CON DATOS DE LOS CUALES QUIERO CONTAR CUANTAS FILAS CUMPLEN
UNA CONDICION Y QUE ME ARROJE EL RESULTADO EN UN LABEL1.



TENGO UNA COLUMNA NUMERO (2) DE NOMBRE : STATUS, LA CUAL CONTIENE VALORES DE "RECIBIDO" Y "ENTREGADO", QUIERO QUE UN LABEL ME DE EL RESULTADO DE CUANTAS FILAS SON IGUALES A "ENTREGADO", SUPONIENDO QUE TENGO 10 ELEMENTOS Y 5 DE ELLOS DICEN "ENTREGADO", EL NUMERO 5 QUIERO VER EN EL LABEL.

SE ME OCURRE QUE SE DEBE RECORRER TODA LA COLUMNA Y BUSCAR LA COINCIDENCIA SI LA ENCUENTRA QUE SUME, ESTUVE PROBANDO LO SIGUIENTE PERO CREO QUE ME FALLA LA LOGICA ME PUEDEN AYUDAR.

1
2
3
4
5
6
7
8
9
Dim contar As Integer = 0
'recorremos el grid fila por fila
For Each r As DataGridViewRow In DataGridView1.Rows
'en cells() coloco la columna que quiero validar si es igual a la condicion
If r.Cells(2).Value = "ENTREGADO" Then
contar =contar+1
End If
Next
LABEL1.TEXT=contar


no me da error pero tampoco ejecuta el codigo, lo estoy colocando en el form_load, ya que deceo que elvalor del label cambie de acuerdo a cuantos entregados hay.


id status
1 entregado
2 entregado
3 recibido
4 entregado
5 recibido
6 recibido
7 entregado
8 recibido
9 entregado
10 recibido


usted tiene: 5 :piezas entregadas