Tom Powers
asked on
VB.net listview sort to name from selected dropdown box
Hey I am working on a Windows App in Vb.net where I load a Dropdown box and a Listview with Printers from a Printserver.
I can do this if it were pulling data from a database but the goal is to type in dropdown the Printername and dropdown autocompletes like a Google Search My Challenge is when dropdown is selected I want listview to filter to the name in dropdown.
Here is the visyuals and code. I don't know how to sort to printer in listview.
Here are the Print names next to Icon of Printer
Any Help with the VB Contex would be much appreciated.Thank You
I can do this if it were pulling data from a database but the goal is to type in dropdown the Printername and dropdown autocompletes like a Google Search My Challenge is when dropdown is selected I want listview to filter to the name in dropdown.
Here is the visyuals and code. I don't know how to sort to printer in listview.
Here are the Print names next to Icon of Printer
Public Sub Printers()
Dim options As ConnectionOptions
options = New ConnectionOptions
options.Username = "xxxxxx"
options.Password = "xxxxxxxxxxxx"
LSPrinters.Clear()
'* Test the connection
' Dim ps() As Services
LSPrinters.BeginUpdate()
LSPrinters.Columns.Add("", 150, HorizontalAlignment.Center)
LSPrinters.Columns.Add("Name", 150, HorizontalAlignment.Left)
LSPrinters.Columns.Add("DriveName", 250, HorizontalAlignment.Left)
LSPrinters.Columns.Add("Location", 250, HorizontalAlignment.Left)
LSPrinters.Columns.Add("Port Name", 200, HorizontalAlignment.Left)
' LSPrinters.Columns.Add("Document", 150, HorizontalAlignment.Left)
' LSPrinters.Columns.Add("Jobstatus", 150, HorizontalAlignment.Left)
'' LSPrinters.Columns.Add("PagesPrinted", 150, HorizontalAlignment.Left)
' LSPrinters.Columns.Add("TotalPages", 200, HorizontalAlignment.Left)
' LSPrinters.Columns.Add("Status", 150, HorizontalAlignment.Left)
On Error Resume Next
Dim scope As ManagementScope
scope = New ManagementScope("\\" & Computername & "\root\cimv2", options)
scope.Connect()
Dim query As ObjectQuery
query = New ObjectQuery("SELECT * FROM Win32_Printer")
On Error Resume Next
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(scope, query)
Dim queryCollection As ManagementObjectCollection
queryCollection = searcher.Get()
On Error Resume Next
Dim m As ManagementObject
For Each m In queryCollection
Dim lvi As ListViewItem = New ListViewItem()
tscmbPrinters.Items.Add(m.GetPropertyValue("Name").ToString())
tsLoc.Text = (m.GetPropertyValue("Location").ToString())
If tsLoc.Text = "" Then
' Dim listItem As New ListViewItew.Add(p.ProcessName.ToString())
lvi.ImageIndex = 0
lvi.SubItems.Add(m.GetPropertyValue("ShareName").ToString())
lvi.SubItems.Add(m.GetPropertyValue("DriverName").ToString())
lvi.SubItems.Add("Not Listed").ToString()
lvi.SubItems.Add(m.GetPropertyValue("Portname").ToString())
' PrintersJob()
LSPrinters.Items.Add(lvi)
tsLoc.Text = ""
Else
' Dim listItem As New ListViewItew.Add(p.ProcessName.ToString())
lvi.ImageIndex = 0
lvi.SubItems.Add(m.GetPropertyValue("ShareName").ToString())
lvi.SubItems.Add(m.GetPropertyValue("DriverName").ToString())
lvi.SubItems.Add(m.GetPropertyValue("Location").ToString())
lvi.SubItems.Add(m.GetPropertyValue("Portname").ToString())
' PrintersJob()
LSPrinters.Items.Add(lvi)
tsLoc.Text = ""
End If
Next
LSPrinters.EndUpdate()
m = Nothing
End Sub
Any Help with the VB Contex would be much appreciated.Thank You
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help I give you an assist I actually found what I was after Just using a populated Listview
Private Function FindItem(ByVal LV As ListView, ByVal TextToFind As String) As Integer
' Loop through LV’s ListViewItems.
For i As Integer = 0 To LV.Items.Count - 1
If Trim(LV.Items(i).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
For subitem As Integer = 0 To LV.Items(i).SubItems.Count - 1
If Trim(LV.Items(i).SubItems(subitem).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
Next
Next
' If not found, then return -1. Return -1
End Function
Public Sub FindPrinter()
LSPrinters.MultiSelect = False
LSPrinters.FullRowSelect = True
Dim checkInt As Integer = FindItem(LSPrinters, tscmbPrinters.Text)
If checkInt <> -1 Then
LSPrinters.Items(checkInt).Selected = True
LSPrinters.Focus()
LSPrinters.SelectedItems(0).EnsureVisible()
Else
ToolStripLabel1.Text = "Search string not found"
End If
End Sub
ASKER
Thanks for your help Brother.
ASKER
Open in new window
Printappnotlisted.png