14 March 2011

Create Icon in ListView Component Visual Basic 6

HOW TO Create Icon in ListView Component Visual Basic 6

Simple Way to Add Icon to your Listview Component






1. First of all, You need to add Listview Component

CHOOSE -> Microsoft Windows Common Controls 6.0 (SP6 or later)
But i am using SP6 here.
Note also that you can add more version, but it has some errors while you are in the middle of the Making Program Process.







2. ADD Controls in the form

Add: IMAGELIST  - This is a container for the ICON
ADD: LISTVIEW (you can name it )



In IMAGELIST properties -> TAB (images) 
INSERT Picture(.ico,.gif, .jpg or other small supported file type)


NOTE: PUT key name . Here I set to = myindex





Set Your LISTVIEW : Imagelists Tab(set small to imagelist : the control you added in the form)

Set VIEW to lvwReport



And if everything is set.. You need to code it



'create function like these
'setup cols headers


Private Sub SetupCols()
'-----------------------------------------------------------------------------
                                 
    With ListView1
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "First Name", .Width * 0.25
        .ColumnHeaders.Add , , "Email Address", .Width * 0.25
        .ColumnHeaders.Add , , "ID", 0
    End With


End Sub


Private Sub Form_Activate()
Call SetupCols
Call LoadListView


End Sub

in Form_Activate function it calls Setupcols and loadlistview






'-----------------------------------------------------------------------------
Private Sub LoadListView()
'-----------------------------------------------------------------------------
    Dim CurrLI   As ListItem
    Dim fname As String
    
    fname = "MabZiCLe" 'static value
'you may also want to fetch it to other database using SQL syntax
' sql query here
' Example: SELECT * FROM members



   ListView1.ListItems.Clear


' FORMAT: ListView1.ListItems.Add(index,key,text,icon,smallicon)
'smallicon = name set in the imagelist


Set CurrLI = ListView1.ListItems.Add(, , fname & "", , "myindex")
            CurrLI.SubItems(1) = "TEst" & ""
            CurrLI.SubItems(2) = "1000" & "" 'use for queries and other manipulation of data
    
    With ListView1
        If .ListItems.Count > 0 Then
            Set .SelectedItem = .ListItems(1)
           
        End If
    End With




End Sub



Sample OUTPUT


Sample Running Code: Create Icon Listview VB6


You Might Read This:
create simple dynamic report in vb6



ALSO:
Sams Teach Yourself Visual Basic 2010 in 24 Hours Complete Starter Kit (Sams Teach Yourself -- Hours)
Visual Basic 2010 Unleashed
Visual Basic 2010 Programmer's Reference (Wrox Programmer to Programmer)
Microsoft Visual Basic 2010 Step by Step (Step By Step (Microsoft))

Unlock Your Creativity | UnwindsCreate Icon ListView Visual Basic 6
Advertisement


Featured Offers:
Advertisement