Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb 2005 express and listview ?

Posted on 2006-07-13
3
Medium Priority
?
284 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

772 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