Centar za edukaciju-BiH



#11 11.04.2019 12:07
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Postovi:10,639


Predmet:Re: Combobox as you type
Da opisem kako kod mene radi vb studio 2010.
kada unesem recimo "st" dobijem u listi ST KITTS a kada nsatavim i dodam r nece se pojaviti nista.
Znaci radi filter samo dok kucas tacno slova od pocetka.
E dali ti to pase neznam.
Ako hoces ovo deugo onda ti je dobro @Gjoreski preporucio.
Moras tekst polje pa sql za pretragu.
Visaoka je to cijena ako stvarno nemas debeo razlog.
Po meni ****lje uzet list box te iznad njega tekst box kao filter
U filter kucas dok u listi ne dobijes uzak izbor koliko ti odgovara.
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.
↑  ↓

#12 11.04.2019 14:27
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


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
↑  ↓

#13 11.04.2019 20:35
Gjoreski Van mreze
Administrator
Registrovan od:02.02.2009
Postovi:1,851


Predmet:Re: Combobox as you type
Evo ova ce resiti problem sa prelaz od text box na list box

PreuzmiIzvorni kôd (Visual Basic):
  1.  Private Sub txtBaraj_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBaraj.KeyDown
  2.         Select Case e.KeyCode
  3.             Case Keys.Return
  4.                 MsgBox("Skoci na gridu sa enter")
  5.                 Me.grdArtikli.Select()
  6.             Case Keys.Down
  7.                 MsgBox("Skoci na listBox sa strelica")
  8.         End Select
  9.     End Sub

Sve odredis na dogadzaj Enter ili strelice
Upises trazena vrednost u txtboxu i sa enter ili strelica se prebacis na lisboxu izaberes vrednost i opet sa enter ili strelica izades is fokusa list boxu i ides na sledeo pole i button .
Ovaj post je ureden 1 puta. Posljednja izmjena 11.04.2019 20:41 od strane Gjoreski. ↑  ↓

#14 12.04.2019 12:03
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


Predmet:Re: Combobox as you type
Da li postoji neko rešenje za ovo:

ON 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)
AutoComp.Clear()

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
**********************************************
ovde mi treba pomoć
ON TEXTCHANGE da primenim filter na AutoComp "[Naziv] like '%" & TextBox1.Text.Trim() & "%'" i dobijem rezultat isto kao i na listbox.
↑  ↓

#15 16.04.2019 14:04
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


Predmet:Re: Combobox as you type
Evo rešenja Smiling
Nadam se da će nekome uÅ¡tedeti 10 dana pretrage

Private listOnit As List(Of String) = New List(Of String)()
Private listNew As List(Of String) = New List(Of String)()

'********************************
Private Sub BindComboBox()

Dim strconn As String = "Data Source=10.10.60.83;Initial Catalog=INIT_DB;User ID=***;password=***"
Dim conn As New SqlConnection(strconn)
Dim cmd As New SqlCommand("SELECT Naziv FROM Kupci Order by Naziv", conn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "listOnit")
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
listOnit.Add(ds.Tables(0).Rows(i)(0).ToString())

Next

Me.nazivdm_combo.Items.AddRange(listOnit.ToArray())
End Sub
'********************************
_Load

BindComboBox()
'********************************
Private Sub nazivdm_combo_TextUpdate(sender As Object, e As EventArgs) Handles nazivdm_combo.TextUpdate

Me.nazivdm_combo.Items.Clear()
listNew.Clear()
Me.nazivdm_combo.DroppedDown = True
For Each item In listOnit

If item.Contains(Me.nazivdm_combo.Text) Then
listNew.Add(item)
End If
Next

Me.nazivdm_combo.Items.AddRange(listNew.ToArray())
Me.nazivdm_combo.SelectionStart = Me.nazivdm_combo.Text.Length
Cursor = Cursors.[Default]

End Sub
'********************************
Private Sub nazivdm_combo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles nazivdm_combo.KeyPress
If Char.IsLetter(e.KeyChar) Then

e.KeyChar = Char.ToUpper(e.KeyChar)

End If
End Sub
Ovaj post je ureden 1 puta. Posljednja izmjena 16.04.2019 14:05 od strane xl_kid. ↑  ↓

#16 17.04.2019 22:28
Gjoreski Van mreze
Administrator
Registrovan od:02.02.2009
Postovi:1,851


Predmet:Re: Combobox as you type
Interesantno e ovo ali malo je cudno kako kao radi , ima tu par klasi koi su koristene.
Kad imam malo vremena testiracu ovo da vidim kako radi.
Dobro je da si nasao adekvatno resejne na problema.
↑  ↓

#17 18.04.2019 08:37
xl_kid Van mreze
Clan
Registrovan od:11.11.2008
Postovi:154


Predmet:Re: Combobox as you type
Možda je potrebno dodati neki "imports" a nisam siguran za ovo
Public Sub New()
InitializeComponent()
End Sub
radio sam u spageti codu Smiling
Kod mene radi i to je ono Å¡to mi je potrebno.
↑  ↓

Stranice (2):1,2


Sva vremena su GMT +02:00. Trenutno vrijeme: 7: 43 am.