Solved

vb 2005 express and listview ?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

713 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