Add all the rows that you have in your database to the Combobox items.
Note: On my project this search form is one for itself, and then it searches on another form, so you have to make this under the same form as where your listview is!
Below 'Public Class (YourProjectName)' add the following code:
PHP Code
<?php Dim ds As New DataSet Dim strSQL As String Dim cmd As New MySqlCommand Dim dr As MySqlDataReader Dim a, b, c, d, f, g, h, i, j, k Dim ConnString As String = "SERVER = localhost; USERID = root; PASSWORD = root; DATABASE = dbname" Dim CONNECTION As New MySqlConnection(ConnString)
Add as many letters as your listview columns has.
After this double click on the textbox, make sure that it handles TextChanged! Now add this code:
PHP Code
<?php Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
strSQL = "SELECT * from dbname where " & ComboBox1.Text & " like '%" & TextBox1.Text & "%'" CONNECTION.Open() cmd = New MySqlCommand(strSQL, CONNECTION) dr = cmd.ExecuteReader()
ListView1.Items.Clear()
Do While dr.Read()
a = (dr.Item("column1").ToString()) b = (dr.Item("column2").ToString()) c = (dr.Item("column3").ToString()) d = (dr.Item("column4").ToString()) f = (dr.Item("column5").ToString()) g = (dr.Item("column6").ToString()) h = (dr.Item("column7").ToString())
Dim lv As ListViewItem = ListView1.Items.Add(a) lv.SubItems.Add(b) lv.SubItems.Add(c) lv.SubItems.Add(d) lv.SubItems.Add(f) lv.SubItems.Add(g) lv.SubItems.Add(h)
Loop dr.Close() CONNECTION.Close() cmd.Dispose()
End Sub
Edit the column1 and the others to your database column names!
Sep 2, 2012 12:15 AM (This post was last modified: Sep 2, 2012 12:16 AM by 0xDEAD10CC.)
(Sep 2, 2012 12:02 AM)Meerkat. Wrote: Why use MySQL for searching in a listview?
Code
Dim FoundItem as ListViewItem = ListView.FindItemWithText()
Hurr durr
You have to be able to add the items back after you clear them out from the search filtering. Unless you want to keep a variable with the full collection of ListViewItems as reference the whole time?
It would be a lot better to simply make a small php file to handle the data sent and received from the mysql database not to mention a lot more secure.
(Dec 29, 2012 09:34 AM)System[X] Wrote: Why use MySql.Data.dll ?
It would be a lot better to simply make a small php file to handle the data sent and received from the mysql database not to mention a lot more secure.
Thanks
Made this along time ago, when i havent learned PHP yet. But now Im using PHP to connect to MySQL databases :)