Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/03/2011, 19:41
Avatar de TECKNOCK
TECKNOCK
 
Fecha de Ingreso: agosto-2010
Mensajes: 80
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Datos duplicados en datagrid vb.net

Hazlo en el mismo evento CellContentDoubleClick. Supongamos que el nombre de tu columna es Tipo_Carne, recorres todo el DataGrid2 buscando el dato en esa columna y asignas SI o NO a una variable FLAG* para saber si se puede agregar o no.

Aqui te dejo el codigo:


Código vb:
Ver original
  1. Private Sub DataGrid1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.CellContentDoubleClick
  2. 'Iniciamos nuestro FLAG en SI
  3. Dim Agregar As String = "SI"
  4. 'Buscamos en todas las FILAS del DataGrid2
  5. For Each FILA As DataGridViewRow In DataGrid2.Rows
  6. If FILA.Cells("Tipo_Carne").Value = DataGrid1.CurrentCell.Value Then
  7. Agregar = "NO"
  8. Exit For
  9. End If
  10. Next
  11. 'Si el FLAG esta en SI agregamos la fila del DAtaGrid1 en el DataGrid2
  12. If Agregar = "SI" Then
  13. DataGrid2.Rows.Add(DataGrid1.CurrentRow)
  14. Else
  15. MsgBox("Este dato ya fue agregado.")
  16. End If
  17. End Sub

* Variable FLAG: Es una variable que sirve como un indicador para decidir cuando debe ocurrir una accion.

Última edición por TECKNOCK; 14/03/2011 a las 19:51