Solved

vb 2005 express and listview ?

Posted on 2006-07-13
3
269 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 62

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 62

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now