Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/04/2010, 19:45
Avatar de jaullo
jaullo
 
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: llenar combobox en vb.net 2005

Hola visualting, primero que nada debes separar el llenar un combo de buscar mientras de escribe.

Para llenar el combo puedes usar algo asi
'cargo el combo con los nombres del producto
Function cargaproducto()

Dim dataset1 As New DataSet
objaux.traer_datos(dataset1, "select * from xxx where id_status=1")
cboProducto.DataSource = dataset1.Tables(0)
cboProducto.DisplayMember = "descripcion".ToString
cboProducto.ValueMember = "descripcion".ToString
End Function

Para buscar mientras se escribe (en el evento keyup del combo)

Public Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String

'Allow select keys without Autocompleting

Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
Return
End Select

'Get the Typed Text and Find it in the list

sTypedText = cbo.Text
iFoundIndex = cbo.FindString(sTypedText)

'If we found the Typed Text in the list then Autocomplete

If iFoundIndex >= 0 Then

'Get the Item from the list (Return Type depends if Datasource was bound

' or List Created)

oFoundItem = cbo.Items(iFoundIndex)

'Use the ListControl.GetItemText to resolve the Name in case the Combo

' was Data bound

sFoundText = cbo.GetItemText(oFoundItem)

'Append then found text to the typed text to preserve case

sAppendText = sFoundText.Substring(sTypedText.Length)
cbo.Text = sTypedText & sAppendText

'Select the Appended Text

cbo.SelectionStart = sTypedText.Length
cbo.SelectionLength = sAppendText.Length

End If

End Sub

Saludos