Visual Basic.NET - BUSCAR EN UN DATAGRID

 
Vista:

BUSCAR EN UN DATAGRID

Publicado por Ricardo Padrino (5 intervenciones) el 29/04/2005 20:48:27
TENGO UN DATAGRID CON 5 COLUMNAS, LA PRIMERA COLUMNA CONTIENE LOS CODIGOS DE CLIENTES, Y TENGO UN TEXTBOX, AL COLOCAR EN EL TEXTBOX UN CODIGO DE CLIENTE, DESEO QUE ESTE ME LO BUSQUE EN EL DATAGRID Y ME LO APUNTE.

GRACIAS A LAS PERSONAS QUE ME PUEDAN AYUDAR.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:BUSCAR EN UN DATAGRID

Publicado por Harold (411 intervenciones) el 01/05/2005 02:00:53
'Espero te ayude.....

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
Dim myTable As DataTable
Dim xd As Integer
search = TextBox1.Text
myTable = CType(DataGrid1.DataSource, DataTable)
For xd = 1 To myTable.Rows.Count - 1
If DataGrid1.Item(xd, 0) = search Then
DataGrid1.Select(xd)
DataGrid1.CurrentRowIndex = (xd)
End If
Next
End If
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:BUSCAR EN UN DATAGRID

Publicado por donkirk (17 intervenciones) el 24/06/2005 13:26:15
Otra opcion modificando el codigo de Harold:

Dim anterior As Integer

Private Sub TextNombreTitular_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextNombreTitular.TextChanged
If TextNombreTitular.Text.Length > 0 Then
Dim TablaParaSeleccion As DataTable
Dim n As Integer
TablaParaSeleccion = CType(datagrid1.DataSource, DataTable)
For n = 0 To TablaParaSeleccion.Rows.Count - 1
If Mid(datagrid1.Item(n, 1), 1, TextNombreTitular.Text.Length) = TextNombreTitular.Text Then
If IsNothing(anterior) = False Then
datagrid1.UnSelect(anterior)
End If
datagrid1.Select(n)
datagrid1.CurrentRowIndex = n
anterior = n
Exit For
End If
Next
TablaParaSeleccion.Dispose()
n = Nothing
End If
End Sub

===============================================================

Esto recorre el datagrid seleccionando unicamente el registro q va encajando con lo q se va escribiendo en el textbox y deseleccionando el registro anterior, pq compara la misma cantidad de caracteres q escribes con esa misma cantidad de caracteres del campo de los registros.

Espero q sirva de ayuda, un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar