Mi problema es la carga de datos en el Datagridview demora mucho este es mi código..
http://sia1.subirimagenes.net/img/2...343230.jpg
Option Strict On
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class BusquedaRespon
Private iniciando As Boolean = True
Private dt As DataTable
Private conexion As String = "Data Source = (local); " & "Initial Catalog=demoDB; " & "Integrated Security=true"
Private seleccion As String = "SELECT CODPSAL, NOMBRE FROM MSTRPERS"
Private da As SqlDataAdapter
Private Sub Busqueda_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.txtApellidos.Text = ""
da = New SqlDataAdapter(seleccion, conexion)
dt = New DataTable
da.Fill(dt)
Me.datosClientes.DataSource = dt
iniciando = False
End Sub
Private Sub txtApellidos_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtApellidos.TextChanged
If iniciando Then Exit Sub
Dim filas() As DataRow
filas = dt.Select("NOMBRE LIKE '%" & txtApellidos.Text & "%'")
Me.listaApellidos.Items.Clear()
If filas.Length > 0 Then
For Each dr As DataRow In filas
Me.listaApellidos.Items.Add(dr("NOMBRE").ToString & ", " & dr("CODPSAL").ToString)
Next
End If
End Sub
Private Sub listaApellidos_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles listaApellidos.SelectedIndexChanged
If iniciando Then Exit Sub
Me.txtApellidos.Text = Me.listaApellidos.SelectedItem.ToString
Me.datosClientes.ClearSelection()
For Each fila As DataGridViewRow In Me.datosClientes.Rows
If fila.Cells("NOMBRE").Value Is Nothing OrElse fila.Cells Is Nothing Then
Continue For
End If
Dim s As String = fila.Cells("NOMBRE").Value.ToString
If String.IsNullOrEmpty(s) = False Then
If s = Me.txtApellidos.Text Then
Me.datosClientes.Rows(fila.Index).Selected = True
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
End If
If Me.txtApellidos.Text = fila.Cells("NOMBRE").Value.ToString Then
Me.datosClientes.Rows(fila.Index).Selected = True
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
If Me.txtApellidos.Text.StartsWith(fila.Cells("NOMBRE").Value.ToString) Then
Me.datosClientes.Rows(fila.Index).Selected = True
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
Dim i As Integer = Me.txtApellidos.Text.IndexOf(",")
If i > -1 Then
' En este ejemplo, el formato es Apellidos, Nombre
Dim nombre, apellidos As String
apellidos = Me.txtApellidos.Text.Substring(0, i).TrimEnd()
nombre = Me.txtApellidos.Text.Substring(i + 1).TrimStart()
If nombre = fila.Cells("CODPSAL").Value.ToString _
AndAlso apellidos = fila.Cells("NOMBRE").Value.ToString Then
' Seleccionamos la fila
Me.datosClientes.Rows(fila.Index).Selected = True
' nos aseguramos de que sea visible
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
Else
If Me.txtApellidos.Text = fila.Cells("NOMBRE").Value.ToString Then
' Seleccionamos la fila
Me.datosClientes.Rows(fila.Index).Selected = True
' nos aseguramos de que sea visible
Me.datosClientes.FirstDisplayedScrollingRowIndex = fila.Index
Exit For
End If
End If
Next
End Sub