Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/01/2010, 14:26
Sonsuke
 
Fecha de Ingreso: diciembre-2007
Mensajes: 5
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Ayuda al buscar un dato repetido en un Datagridview

Gracias por la respuesta comentar tambien que funciona de esta otra forma igual

Código:
'Contador
Private vldContador As Double = 0

Private Sub oTx_BuscaNombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles oTx_BuscaNombre.KeyPress
        Dim i As Double
        Dim posicion As Double
        Dim vlsNombre As String
        Dim vlsComparar As String


        If e.KeyChar = ChrW(Keys.Enter) Then
            vlsComparar = UCase(oTx_BuscaNombre.Text)
            For i = vldContador To oGvDatosClase.RowCount - 1
                vlsNombre = oGvDatosClase.Rows(i).Cells("NOMBRE").Value
                posicion = InStr(vlsNombre, vlsComparar)
                If posicion <> 0 Then
                    oGvDatosClase.Rows(i).Selected = True
                    oGvDatosClase.Rows(i).Selected = i
                    vldContador = i + 1
                    Exit For
                End If
            Next
        End If

        If e.KeyChar = ChrW(Keys.Back) Or e.KeyChar = ChrW(Keys.Delete) Then
            vldContador = 0
        End If
    End Sub
lo que me ocurre ahora es al tener

Cod Nombre
1 Alambre
2 Cobre
3 Alfombra
4 Tubo
5 Alicate
6 Alambre
7 Ampolleta
...

100 Albañileria

al poner "Al" salta por todos los elementos pero en el 100 en el datagridview lo hace pero el scroll no baja a esa posicion



Edito: agregando esta propiedad se logra FirstDisplayedScrollingRowIndex


Código:
'Contador
Private vldContador As Double = 0

Private Sub oTx_BuscaNombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles oTx_BuscaNombre.KeyPress
        Dim i As Double

        'Si ocupamos la 2º forma
        '-------------------------------------------
        Dim posicion As Double        
        Dim vlsNombre As String
        Dim vlsComparar As String
        '--------------------------------------------


        If e.KeyChar = ChrW(Keys.Enter) Then
            
            'Si ocupamos la 2º forma
            vlsComparar = UCase(oTx_BuscaNombre.Text)

            For i = vldContador To oGvDatosClase.RowCount - 1
                '1º Forma
                 If Convert.ToString(oGvDatosClase.Rows(i).Cells("NOMBRE").Value).Contains(UCase(oTx_BuscaNombre.Text)) Then
                    oGvDatosClase.Rows(i).Selected = True
                    oGvDatosClase.Rows(i).Selected = i
                    oGvDatosClase.FirstDisplayedScrollingRowIndex = i
                    vldContador = i + 1
                    Exit For
                End If

                 'o pueden ocupar esta 2º Forma de igual manera
                vlsNombre = oGvDatosClase.Rows(i).Cells("NOMBRE").Value
                posicion = InStr(vlsNombre, vlsComparar)
                If posicion <> 0 Then
                    oGvDatosClase.Rows(i).Selected = True
                    oGvDatosClase.Rows(i).Selected = i
                    oGvDatosClase.FirstDisplayedScrollingRowIndex = i
                    vldContador = i + 1
                    Exit For
                End If
            Next
        End If

        If e.KeyChar = ChrW(Keys.Back) Or e.KeyChar = ChrW(Keys.Delete) Then
            vldContador = 0
        End If
    End Sub
ahi ordene el codigo y que ojala le sirva a alguien mas, agregue la solucion de eperedo igual

Saludos

Última edición por Sonsuke; 07/01/2010 a las 15:02