|
-
Dec 27th, 2011, 08:31 AM
#1
Thread Starter
Fanatic Member
ListBox Search with TextBox
I have an web reference application which have combox added with server1 and server2 .. server2 is triggered in form load event..
when while debugging server1 or server2 class is called and its items are invoked in listbox.. as I have shown in fig.
I want to make Listbox search with TextBox. so that when user puts product number in textbox and hit enter only that product number should be searched .
please help me
-
Dec 27th, 2011, 09:22 AM
#2
Re: ListBox Search with TextBox
basically it depends on how you are filling the listbox,
just go through the code & note please
(1) i have a listbox & a textbox control
(2) declared a binding source + datatable
(3) filled the data ( in your case data from server 1,2 etc..) in to a datatble
(4) next i am filtering the listbox contents with textbox text
fallow the code
vb Code:
Public Class Form1 Dim Bs As New BindingSource Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Dt As New DataTable Dt.Columns.Add("ProductID", Type.GetType("System.String")) Dim Row As DataRow Dim i As Integer With Dt For i = 0 To 10 Row = .NewRow Row("ProductID") = "product " & i .Rows.Add(Row) Next i End With Bs.DataSource = Dt Me.ListBox1.DataSource = Bs ListBox1.DisplayMember = "ProductID" End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim sEARCHsTRING As String = Me.TextBox1.Text With Me.Bs .Filter = "ProductID Like '" & sEARCHsTRING & "%'" End With End Sub End Class
-
Dec 28th, 2011, 11:45 AM
#3
Thread Starter
Fanatic Member
Re: ListBox Search with TextBox
thanks but I get 3 Errors
Code:
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Dt As New DataTable
Dt.Columns.Add("productid", Type.GetType("System.String"))
Dim Row As DataRow
Dim i As Integer
With (Dt)
For i = 0 To 10
Next
Row = .NewRow
Row("productid") = "product " & i
Rows.Add(Row)
Next i
End With
Bs.DataSource = Dt
Me.ListBox.DataSource = Bs
ListBox.DisplayMember = "productid"
End Sub
Error 1. Name 'Rows' is not declared.
Error 2. 'Next' must be preceded by a matching 'For'.
Code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim sEARCHsTRING As String = Me.TextBox1.Text
With (Me.Bs)
Filter = "productid Like '" & sEARCHsTRING & "%'"
End With
End Sub
Error 3. Overload resolution failed because no accessible 'Filter' accepts this number of arguments.
please help
-
Dec 28th, 2011, 12:52 PM
#4
Re: ListBox Search with TextBox
read the contents of #2 carefully
this what is there in my code this what in your code dot is missing
next
this is what your code
For i = 0 To 10
Next
Row = .NewRow
Row("productid") = "product " & i
Rows.Add(Row)
Next i
see care fully in my code & yours , i have highlighted the mistakes
i believe that you have copy'd & pasted but failed to read & check my code
-
Dec 28th, 2011, 01:11 PM
#5
Thread Starter
Fanatic Member
Re: ListBox Search with TextBox
THANK you very much .. I m really sorry!
but what about error. 3 .. about Filter Please Solve this also
-
Dec 28th, 2011, 01:21 PM
#6
Re: ListBox Search with TextBox
i would like to repeat to recheck #2 carefully
this your code
Code:
With (Me.Bs)
Filter = "productid Like '" & sEARCHsTRING & "%'"
End With
this is mine
Code:
With (Me.Bs)
.Filter = "productid Like '" & sEARCHsTRING & "%'"
End With
code
next importantly Google for what is overload resolution
-
Dec 28th, 2011, 01:37 PM
#7
Thread Starter
Fanatic Member
Re: ListBox Search with TextBox
thanks .. but with no errors..
not succeed when inserting product number in textbox .. after hitting enter no response.. .... listbox is as filled with the items ...
-
Dec 28th, 2011, 01:44 PM
#8
Re: ListBox Search with TextBox
presumably since your listbox contains some lenth of text also like product details...No[123456]
you need to concatenate your text box text with this , ofcourse if you are entering only numbers.
do some thing like
vb Code:
textbox1.text = "product details...No[" & textbox1.text & "]"
and then try
-
Dec 30th, 2011, 12:55 AM
#9
Re: ListBox Search with TextBox
This is the same code posted by make_me_rain in post#2. I have made only 2 changes. Create a new project, add a ListBox and a TextBox into the form. Then copy-paste this code and test it. Type a product number (say "10") in the TextBox and see how it works.
Code:
Public Class Form1
Dim Bs As New BindingSource
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim sEARCHsTRING As String = Me.TextBox1.Text
With Me.Bs
.Filter = "ProductID Like '%" & sEARCHsTRING & "%'"
End With
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Dt As New DataTable
Dt.Columns.Add("ProductID", Type.GetType("System.String"))
Dim Row As DataRow
Dim i As Integer
With Dt
For i = 0 To 10
Row = .NewRow
Row("ProductID") = "Product Details ...No..[" & i & "]"
.Rows.Add(Row)
Next i
End With
Bs.DataSource = Dt
Me.ListBox1.DataSource = Bs
ListBox1.DisplayMember = "ProductID"
End Sub
End Class

Edit:
Same code. But little bit of rearranging, renaming and commenting:
vb.net Code:
Public Class Form1
Dim bs As New BindingSource
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim strSearch As String = Me.TextBox1.Text
bs.Filter = "ProductID Like '%" & strSearch & "%'"
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim row As DataRow
Dim i As Integer
dt.Columns.Add("ProductID", Type.GetType("System.String"))
'~~~ Fill up some sample data
For i = 0 To 10
row = dt.NewRow '~~~ create a new data row
row("ProductID") = "Product Details ...No..[" & i & "]" '~~~ insert value to this row
dt.Rows.Add(row) '~~~ add this row to our DataTable
Next i
'~~~ bind it
bs.DataSource = dt
Me.ListBox1.DataSource = bs
ListBox1.DisplayMember = "ProductID"
End Sub
End Class
Last edited by akhileshbc; Dec 30th, 2011 at 01:05 AM.
Reason: added rearranged code
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Dec 30th, 2011, 09:04 AM
#10
Thread Starter
Fanatic Member
Re: ListBox Search with TextBox
how do I use vbcode tag to post my codes
-
Dec 30th, 2011, 09:14 AM
#11
Re: ListBox Search with TextBox
just type [[HIGHLIGHT]] your complete code goes in between these two highlight & /highlight tags tags[[//HIGHLIGHT]]
Last edited by make me rain; Dec 30th, 2011 at 09:18 AM.
-
Dec 31st, 2011, 06:22 PM
#12
Re: ListBox Search with TextBox
 Originally Posted by make me rain
just type [[HIGHLIGHT]] your complete code goes in between these two highlight & /highlight tags tags[[//HIGHLIGHT]]
Or, click on the VBCode icon( ), when you post it. And an inputbox will popout. Enter "vb.net". This will create the [HIGHLIGHT] tags for you. If you have the code already pasted in the editor and it is selected, then by doing the above will enclose that selection in [HIGHLIGHT] tags.
Eg:
Code:
[HIGHLIGHT="vb.net"]
'~~~ vb.net code here
MessageBox.Show("Hi janu...")
[/HIGHLIGHT]
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|