Predmet:Re: Combobox as you type
Private Sub Narudzbe_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strconn As String = "Data Source=10.10.60.83;Initial Catalog=INIT_DB;User ID=***;password=***"
Dim conn As New SqlConnection(strconn)
Dim command As New SqlCommand("SELECT * FROM Kupci")
command.Connection = conn
Dim adapter As New SqlDataAdapter(command)
Dim table As New DataTable()
adapter.Fill(table)
ListBox1.DataSource = table
ListBox1.DisplayMember = "Naziv"
ListBox1.ValueMember = "ID"
ListBox1.SelectedItems.Clear()
If TextBox1.Text <> "" Then
Dim count As Integer = (ListBox1.Items.Count - 1)
Dim words As String
For a = 0 To count
words = ListBox1.Items.Item(a)
If words.ToLower.StartsWith(TextBox1.Text.ToLower) Then
ListBox1.SelectedItems.Add(ListBox1.Items.Item(a))
End If
Next
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
ListBox1.DataSource.DefaultView.RowFilter = "[Naziv] like '%" & TextBox1.Text.Trim() & "%'"
End Sub
ovo radi i dobijem traženu pretragu. Problem mi je sledeći. Kako da prebacim fokus na listu?
ili drugi primer koji je ono želim da postignem
Private Sub Narudzbe_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim AutoComp As New AutoCompleteStringCollection()
Dim dsSerch As New DataSet
Dim ConStr As String = "Data Source=10.10.60.83;Initial Catalog=INIT_DB;User ID=***;password=***"
Dim sqlCon As New SqlClient.SqlConnection(ConStr)
sqlCon.Open()
Dim Str As String = "Select Naziv FROM Kupci"
Dim SqlCom As New SqlClient.SqlCommand(Str, sqlCon)
Dim sqlAdap As New SqlClient.SqlDataAdapter(SqlCom)
sqlAdap.Fill(dsSerch)
For i As Integer = 0 To dsSerch.Tables(0).Rows.Count - 1
AutoComp.Add(dsSerch.Tables(0).Rows(i)(0).ToString())
Next
TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
TextBox1.AutoCompleteCustomSource = AutoComp
End Sub
kao reziltat dobijam samo prve karaktere ali ne i deo reči. recimo za ST dobijem STRUMICA ali ne i AUSTRIA. Da li ima neko reÅ¡enja da mi TextBox1.AutoCompleteCustomSource bude rezultat kao i za listbox