Ver Mensaje Individual
  #16 (permalink)  
Antiguo 09/06/2011, 07:14
Avatar de Aquaventus
Aquaventus
 
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 13 años, 10 meses
Puntos: 267
Respuesta: de un texbox a un datagrid

a simple vista vi tu error, Comenta todo lo que esta dentro del TextChanged, porque cada vez que digites va a mandar un "enter" y eso es lo que te ingresaba a cada rato a tu listview, y descomenta la validacion de las teclas, entonces te quedaria así :

Código vb.net:
Ver original
  1. Imports System.Data.SqlClient
  2. Public Class VentaLibros
  3.     Private myConn As New SqlConnection
  4.     Private myCmd As New SqlCommand
  5.     Private myReader As SqlDataReader
  6.     Private results As String
  7.     Dim adaptor As New SqlClient.SqlDataAdapter
  8.     Dim dataset As New DataSet
  9.     Private Sub VentaLibros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.  
  11.     End Sub
  12.  
  13.     Private Sub TbProducto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TbProducto.KeyPress
  14.         'Valido que se ingrese solo numeros
  15.  
  16.         If Char.IsNumber(e.KeyChar) Then
  17.             e.Handled = False
  18.             'Valido que se presione Backspace,Enter
  19.         ElseIf Char.IsControl(e.KeyChar) Then
  20.             e.Handled = False
  21.             'Las demas teclas quedan bloqueadas
  22.         Else
  23.             e.Handled = True
  24.         End If
  25.  
  26.         'Si mando un ENTER entonces que busque
  27.         If e.KeyChar = Convert.ToChar(Keys.Enter) Then
  28.  
  29.             'Aqui ya te encargas de hacer tu busqueda e insertarlo a tu gridview
  30.             myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;")
  31.             'Crear un objeto Command.
  32.             myCmd = myConn.CreateCommand
  33.             myCmd.CommandText = "SELECT * FROM libros WHERE cod_libro ='" & TbProducto.Text & "' "
  34.             myConn.Open()
  35.             myReader = myCmd.ExecuteReader()
  36.             'Ltver.View = View.Details
  37.             'Ltver.Items.Clear()
  38.             Dim j = 0
  39.             Do While myReader.Read()
  40.                 Ltver.Items.Add(Str(myReader.Item("cod_libro")), 0)
  41.                 Ltver.Items(j).SubItems.Add(myReader.Item("nombre_libro"))
  42.                 Ltver.Items(j).SubItems.Add(myReader.Item("precio"))
  43.                 'j = j + 1
  44.             Loop
  45.  
  46.  
  47.             ' Dim j = 0
  48.  
  49.             ' j = Ltver.Items.Contains
  50.  
  51.  
  52.             'Ltver.Items.Add(TbProducto.Text, "cod_libro")
  53.             'Ltver.Items.SubItems.Add("nombre_libro").ToString()
  54.             'Ltver.Items.SubItems.Add("precio").ToString()
  55.             myReader.Close()
  56.             myConn.Close()
  57.             'Ltver.Sort()
  58.         End If
  59.     End Sub
  60.  
  61.     Private Sub TbProducto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TbProducto.TextChanged
  62.         'Por ejemplo yo defino la longitud del codigo, en este caso
  63.         'Si llega a 13
  64.         'If TbProducto.Text.Trim().Length = 13 Then
  65.         '    'Que envie un enter
  66.         '    SendKeys.Send("{Enter}")
  67.         'End If
  68.     End Sub
  69. End Class
Espero haberte ayudado. Saludos!..
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net