Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attach a Icon/Image to a ListView Control

Status
Not open for further replies.

talenx

Programmer
Aug 7, 2001
157
US
OK,
I have been fumbling with this for a while now, and I have not been able to find a good example on how to place a icon/image on a ListView control.

I have done the following:
Created a ImageList object call ImageList1
Place two bmp in it and labeled KEYS check and uncheck.

Set the ListView control to small icons

-----------------------------------------------------
This where I get screwed up....

i have found numerous ways to place the image on the control, but they all failed.


Here is my code.

Private Sub Form_Load()

' Add ColumnHeaders. The width of the columns is
' The width of the control divided by the number of
' ColumnHeader objects.
ListView1.ColumnHeaders.Add , , "Project Name", ListView1.Width / 5
ListView1.ColumnHeaders.Add , , "Market Name", ListView1.Width / 5
ListView1.ColumnHeaders.Add , , "County Name", ListView1.Width / 5
ListView1.ColumnHeaders.Add , , "Builder Name", ListView1.Width / 5
ListView1.ColumnHeaders.Add , , "Architect Name", ListView1.Width / 5
ListView1.ColumnHeaders.Add , , "Tagged", ListView1.Width / 5

' The name of the control is "ListView1"
ListView1.View = lvwReport

' Declare object variables for the
' Data Access objects.
Dim myDb As Database, myRs As Recordset

‘Set SQL data source.
Set myDb = CurrentDb
Set myRs = myDb.OpenRecordset(&quot;SELECT * FROM TMGDATA WHERE TMGDATA.[Project ID]<4000&quot;)

' Declare a variable to add ListItem objects.
Dim itmX As ListItem

' Column 1 but will alway be set to Project Name

While Not myRs.EOF
Set itmX = ListView1.ListItems. _
Add(, , CStr(myRs![Project Name]))

' If the Column 2 field is not null, then set
' SubItem 1 to it.

If Not IsNull(myRs![Market Name]) Then
itmX.SubItems(1) = myRs![Market Name]
End If
If Not IsNull(myRs![County Name]) Then
itmX.SubItems(2) = myRs![County Name]
End If
If Not IsNull(myRs![BUILDER]) Then
itmX.SubItems(3) = myRs![BUILDER]
End If
If Not IsNull(myRs![ARCHITECT]) Then
itmX.SubItems(4) = myRs![ARCHITECT]
End If
If Not IsNull(myRs![tagged]) Then
itmX.SubItems(5) = myRs![tagged]
End If

myRs.MoveNext ' Move to next record.
Wend



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top