Solved

vb 2005 express and listview ?

Posted on 2006-07-13
3
277 Views
Last Modified: 2008-01-09
Found this article :

http://www.knowdotnet.com/articles/sortedlistview.html

And I have followed the code on that to suit my needs so that I can load printer name, print job name and owner name into a listview and I have installed 2 fake printers and paused them both and send a print job to each and my code seems to work aside from one bug that I have noticed, if I take the lstJobs.List.Clear command out It works the first time I click the button but if I keep clicking it obviously keeps re adding it in and it duplicates itself, yet when I put it back into the code you only see one of the print jobs from one of the printers and not the other one.

Here is the code that I have so far ( Yes I have made a reference to the systems management ) :

Imports System
Imports System.Management

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oq As New System.Management.ObjectQuery("SELECT * FROM Win32_PrintJob") '
        Dim query1 As New ManagementObjectSearcher(oq)
        Dim queryCollection1 As ManagementObjectCollection = query1.Get()
        Dim mo As ManagementObject
        For Each mo In queryCollection1
            Dim lvi As ListViewItem
            ' lstJobs.Items.Clear()
            With Me.lstJobs

                .Sorting = SortOrder.Ascending
                lvi = .Items.Add(mo("DriverName").ToString())
                lvi.SubItems.Add(mo("Document").ToString())
                lvi.SubItems.Add(mo("Owner").ToString())

                Me.Label1.Text = "ListItem(0).SubItems: " & .Items(0).SubItems.Count
            End With
        Next mo




    End Sub 'Main

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        lstJobs.Columns.Add("Printer", 200, HorizontalAlignment.Center)
        lstJobs.Columns.Add("Document", 200, HorizontalAlignment.Center)
        lstJobs.Columns.Add("Owner", 200, HorizontalAlignment.Center)
    End Sub
End Class
0
Comment
Question by:gecko_au2003
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 17102053
Hi gecko_au2003;

You have the Clear command in the For Each loop so every time it goes for the next item to put in the ListView control it clears it first. Place it befor the loop.
   
    lstJobs.Items.Clear()

Fernando
0
 
LVL 23

Author Comment

by:gecko_au2003
ID: 17102140
Thanks, that would make sense and it works now :)
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17102150
No problem, glad I was able to help. :=)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question