Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the below code where i m connecting to a remote computer to get a list of installed software. The code works fine but its very blan and i want to spice it up with adding a png icon next to specific names. Now i have tested the code with the empty if statement at the bottom by deleting the ones i want to have a special icon linked to i just dont know how i would add a png icon next to StrName.

I have tried adding ListView1.Items(0).ImageIndex = 1 but this didnt work for me.

If someone could help that would be great. I have been looking at this all day and i think i need someone else eyes on it.


VB
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
       Dim objLocator, objService, objRegistry, arrIdentityCode, strIdentityCode, objShell
       Dim strRegIdentityCodes As String
       objLocator = CreateObject("WbemScripting.SWbemLocator")

       Dim strComputer As String = Application.Machine_Name_Textbox_Header.Text
       If Application.Machine_Name_Textbox_Header.Text = "" Then
           strComputer = "127.0.0.1"
       End If

       Try
           objService = objLocator.ConnectServer(strComputer, "Root\Default")
           objService.Security_.impersonationlevel = 3
           objRegistry = objService.Get("StdRegProv")
       Catch ex As Exception

       End Try


       strRegIdentityCodes = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

       Const HKLM = &H80000002

       Dim strRegIdentityInfo, strDisplayName, strDisplayVersion, strInstallDate, strUninstallString, strPublisher

       objRegistry.EnumKey(HKLM, strRegIdentityCodes, arrIdentityCode)
       objShell = CreateObject("WScript.Shell")

       Dim strName As String

       For Each strIdentityCode In arrIdentityCode

           Try

               strRegIdentityInfo = "HKEY_LOCAL_MACHINE\" & strRegIdentityCodes & "\" & strIdentityCode & "\"
               strDisplayName = objShell.RegRead(strRegIdentityInfo & "DisplayName")
               strDisplayVersion = objShell.RegRead(strRegIdentityInfo & "DisplayVersion")
               strInstallDate = InstallDate(objShell.RegRead(strRegIdentityInfo & "InstallDate"))
               strUninstallString = objShell.RegRead(strRegIdentityInfo & "UninstallString")
               strPublisher = objShell.RegRead(strRegIdentityInfo & "Publisher")

               strName = strDisplayName

               Dim item As ListViewItem = New ListViewItem(strName)
               item.SubItems.Add(strDisplayVersion)
               item.SubItems.Add(strInstallDate)
               item.SubItems.Add(strPublisher)
               item.SubItems.Add(strUninstallString)
               item.SubItems.Add(strRegIdentityInfo)
               ListView1.Items.Add(item)

               If (strName.StartsWith("Hotfix") Or strName.StartsWith("Security") Or strName.StartsWith("Update")) Then

               End If

           Catch ex As Exception

           End Try

       Next

   End Sub
Posted
Updated 12-Mar-12 11:10am
v3
Comments
Sergey Alexandrovich Kryukov 11-Mar-12 23:31pm    
What is it: WPF? Forms? Silverlight? What? Please tag it.
--SA
Zachary.shupp 12-Mar-12 17:11pm    
WinForms, sorry i updated the question to reflect winforms.

1 solution

In WinForm, you need to inherit a new control from ListBox. Create a new project in your solution, of the type "Windows Control Library". Here is the code file:

C#
public partial class ListBoxWithBg : ListBox 
{ 
 Image image; 
 Brush brush, selectedBrush; 

 public ListBoxWithBg(String ImageFile) 
 { 
   InitializeComponent(); 
   this.DrawMode = DrawMode.OwnerDrawVariable; 
   this.DrawItem += new DrawItemEventHandler(ListBoxWithBg_DrawItem); 
   this.image = Image.FromFile(ImageFile); 
   this.brush = new SolidBrush(Color.Black); 
   this.selectedBrush = new SolidBrush(Color.White); 
 }
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900