none
Busqueda en datagridview

    Question

  • Hola Foro mi problema es el siguiente:

    Tengo un datagrid ya cargado el problema es que son muchos los registros y si el usuario quiere un nombre que esta a digamos mas alla de la mitad de los registros sera dificil su ubicacion he pensado y no se si se pueda hacer un buscador tradictorio osea que a medida que vala escribiendo el usuario se vallan desglosando los registros correspondientes a su busqueda espero puedan ayudarme, de antemano Gracias.

    Saludos.

    Monday, April 29, 2013 11:29 PM

Answers

  • Hola:

     En un Formulario arrastra un DataGridView, agregale  columnas del tipo TextboxColumn, CheckBoxColumn, y TextBoxColumn, dos botones copia y pega este ejemplo:

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.Rows.Add("Valorno", True, "valor 1")
            DataGridView1.Rows.Add("Valorno", True, "valor 2")
            DataGridView1.Rows.Add("Valorno", True, "valor 3")
            DataGridView1.Rows.Add("Valorno", True, "valor 4")
            DataGridView1.Rows.Add("Valorno", True, "valor 5")
            DataGridView1.Rows.Add("Valorno", True, "valor 6")
            DataGridView1.Rows.Add("Valorno", True, "valor 7")
            DataGridView1.Rows.Add("Valorno", True, "valor 8")
            DataGridView1.Rows.Add("Valorno", True, "valor 9")
            DataGridView1.Rows.Add("Valorno", True, "valor 10")
            DataGridView1.Rows.Add("Valorno", False, "valor 11")
            DataGridView1.Rows.Add("doce", False, "valor 12")
            DataGridView1.Rows.Add("Valorno", False, "valor 13")
            DataGridView1.Rows.Add("Valorno", False, "valor 14")
            DataGridView1.Rows.Add("Valorno", False, "valor 15")
            DataGridView1.Rows.Add("Valorno", False, "valor 16")
            DataGridView1.Rows.Add("Valorno", False, "valor 17")
            DataGridView1.Rows.Add("Valorno", False, "valor 18")
            DataGridView1.Rows.Add("Valorno", False, "valor 19")
            DataGridView1.Rows.Add("Valorno", False, "valor 20")
            DataGridView1.Rows.Add("Valorno", False, "valor 21")
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim query As IEnumerable(Of DataGridViewRow) = _
               From item In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
                 Where CStr(item.Cells("Column3").Value) = "valor 12" _
                   Select item
    
            Dim row As DataGridViewRow = query.FirstOrDefault()
    
            If Not row Is Nothing Then
                ' Asignamos la propiedad CurrentCell 
                ' 
                DataGridView1.CurrentCell = DataGridView1.Item(0, row.Index)
    
                ' Asignamos la propiedad FirstDisplayedCell 
                ' 
                DataGridView1.FirstDisplayedCell = DataGridView1.CurrentCell
    
            End If
    
        End Sub
    
        Private Sub SelectLastPayment()
            Dim query As IEnumerable(Of DataGridViewRow) = _
            From item In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
              Where CBool(item.Cells("Column2").Value) = False _
                Select item
    
            Dim row As DataGridViewRow = query.FirstOrDefault()
    
            If Not row Is Nothing Then
                ' Asignamos la propiedad CurrentCell 
                ' 
                DataGridView1.CurrentCell = DataGridView1.Item(0, row.Index)
                Dim int As Integer = DataGridView1.CurrentCell.RowIndex
    
                ' Asignamos la propiedad FirstDisplayedScrollingRowIndex 
                ' 
                DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.CurrentCell.RowIndex - 3
    
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            SelectLastPayment()
        End Sub
    End Class

     Me dices como te fue!


    Saludos desde Monterrey, Nuevo León, México!!!

    • Marked as answer by juvifra86 Tuesday, April 30, 2013 12:16 AM
    Monday, April 29, 2013 11:46 PM

All replies

  • Hola:

     En un Formulario arrastra un DataGridView, agregale  columnas del tipo TextboxColumn, CheckBoxColumn, y TextBoxColumn, dos botones copia y pega este ejemplo:

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.Rows.Add("Valorno", True, "valor 1")
            DataGridView1.Rows.Add("Valorno", True, "valor 2")
            DataGridView1.Rows.Add("Valorno", True, "valor 3")
            DataGridView1.Rows.Add("Valorno", True, "valor 4")
            DataGridView1.Rows.Add("Valorno", True, "valor 5")
            DataGridView1.Rows.Add("Valorno", True, "valor 6")
            DataGridView1.Rows.Add("Valorno", True, "valor 7")
            DataGridView1.Rows.Add("Valorno", True, "valor 8")
            DataGridView1.Rows.Add("Valorno", True, "valor 9")
            DataGridView1.Rows.Add("Valorno", True, "valor 10")
            DataGridView1.Rows.Add("Valorno", False, "valor 11")
            DataGridView1.Rows.Add("doce", False, "valor 12")
            DataGridView1.Rows.Add("Valorno", False, "valor 13")
            DataGridView1.Rows.Add("Valorno", False, "valor 14")
            DataGridView1.Rows.Add("Valorno", False, "valor 15")
            DataGridView1.Rows.Add("Valorno", False, "valor 16")
            DataGridView1.Rows.Add("Valorno", False, "valor 17")
            DataGridView1.Rows.Add("Valorno", False, "valor 18")
            DataGridView1.Rows.Add("Valorno", False, "valor 19")
            DataGridView1.Rows.Add("Valorno", False, "valor 20")
            DataGridView1.Rows.Add("Valorno", False, "valor 21")
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim query As IEnumerable(Of DataGridViewRow) = _
               From item In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
                 Where CStr(item.Cells("Column3").Value) = "valor 12" _
                   Select item
    
            Dim row As DataGridViewRow = query.FirstOrDefault()
    
            If Not row Is Nothing Then
                ' Asignamos la propiedad CurrentCell 
                ' 
                DataGridView1.CurrentCell = DataGridView1.Item(0, row.Index)
    
                ' Asignamos la propiedad FirstDisplayedCell 
                ' 
                DataGridView1.FirstDisplayedCell = DataGridView1.CurrentCell
    
            End If
    
        End Sub
    
        Private Sub SelectLastPayment()
            Dim query As IEnumerable(Of DataGridViewRow) = _
            From item In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
              Where CBool(item.Cells("Column2").Value) = False _
                Select item
    
            Dim row As DataGridViewRow = query.FirstOrDefault()
    
            If Not row Is Nothing Then
                ' Asignamos la propiedad CurrentCell 
                ' 
                DataGridView1.CurrentCell = DataGridView1.Item(0, row.Index)
                Dim int As Integer = DataGridView1.CurrentCell.RowIndex
    
                ' Asignamos la propiedad FirstDisplayedScrollingRowIndex 
                ' 
                DataGridView1.FirstDisplayedScrollingRowIndex = DataGridView1.CurrentCell.RowIndex - 3
    
            End If
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            SelectLastPayment()
        End Sub
    End Class

     Me dices como te fue!


    Saludos desde Monterrey, Nuevo León, México!!!

    • Marked as answer by juvifra86 Tuesday, April 30, 2013 12:16 AM
    Monday, April 29, 2013 11:46 PM
  • Hola simplemente lo adapte a mi codigo y sirvio el problema es que la palabra a buscar debe estar exactamente igual en el textbox, porque de aqui obtengo el string a buscar, no ahi una manera de que no diferencia entre mayusculas acentos y esas cosas, gracias de antemano, Saludos.
    Tuesday, April 30, 2013 12:18 AM