Solved

vb 2005 express and listview ?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

21 Experts available now in Live!

Get 1:1 Help Now