Hi? I need help in filtering contents in a listview. The list view has several columns but the user is supposed to filter by selecting either "Serial Number" or "Buyer Name" column from a combo box. When the user starts typing in a search textbox, the contents are filtered automatically without hitting any button. The list view contents are from access database and here is my connection code..
And here is how I have porpulated the list view
Sorry, if I have given more than required information, but please correct me if something doesn't look ok.
Code:
Imports System.Data.OleDb
Module Module1
Public Conn As New OleDbConnection
Public MyCmd As New OleDbCommand
Public OleDBDtRdr As OleDbDataReader
Public MyQuerry As String = Nothing
Sub ConnectionToDatabase()
Try
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=PowerMiss.accdb"
.Open()
End With
Catch ex As Exception
MsgBox("Unable to connect to database.", MsgBoxStyle.Exclamation, "Connection Error!")
End Try
End Sub
End module
Code:
Public Class frmSoldUPS
Private Sub frmSoldMachines_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
cmbSearch.Items.Add("Serial Number")
cmbSearch.Items.Add("Buyer Name")
If Conn.State = ConnectionState.Closed Then
MsgBox("Please login first to connect to database.", MsgBoxStyle.Information, "Unable to connect to database.")
Exit Sub
End If
With lvSoldMachines.Columns
.Add("ID", 25, HorizontalAlignment.Left)
.Add("Buyer Name", 150, HorizontalAlignment.Left)
.Add("Buyer location", 100, HorizontalAlignment.Left)
.Add("Branch", 100, HorizontalAlignment.Left)
.Add("RQ No.", 75, HorizontalAlignment.Left)
.Add("DN No.", 75, HorizontalAlignment.Left)
.Add("Date purchased", 100, HorizontalAlignment.Left)
.Add("UPS Brand and Model", 125, HorizontalAlignment.Left)
.Add("Rating 'KVA'", 80, HorizontalAlignment.Left)
.Add("Phases In", 75, HorizontalAlignment.Left)
.Add("Phases out", 75, HorizontalAlignment.Left)
.Add("Serial Number", 100, HorizontalAlignment.Left)
.Add("Purpose", 100, HorizontalAlignment.Left)
End With
FillListView()
End Sub
Public Sub FillListView()
lvSoldMachines.Items.Clear()
MyQuerry = "SELECT * from tblBuyers ORDER BY id ASC"
MyCmd = New OleDbCommand(MyQuerry, Conn)
OleDBDtRdr = MyCmd.ExecuteReader
While OleDBDtRdr.Read
With lvSoldMachines
.Items.Add(OleDBDtRdr("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(OleDBDtRdr("BuyerName"))
.Add(OleDBDtRdr("TownOrLocation"))
.Add(OleDBDtRdr("Branch"))
.Add(OleDBDtRdr("RequisitionNumber"))
.Add(OleDBDtRdr("DeliveryNoteNumber"))
.Add(OleDBDtRdr("DateOfPurchase"))
.Add(OleDBDtRdr("BrandAndModel"))
.Add(OleDBDtRdr("KVARating"))
.Add(OleDBDtRdr("PhasesIn"))
.Add(OleDBDtRdr("PhasesOut"))
.Add(OleDBDtRdr("MachineSerialNumber"))
.Add(OleDBDtRdr("SaleOrStandby"))
End With
End With
End While
End Sub
End class