use two imagelist in listview

User avatar
sal21
PlatinumLounger
Posts: 4344
Joined: 26 Apr 2010, 17:36

use two imagelist in listview

Post by sal21 »

I just have this code to add ion from imagelist in a first column:
Private Sub VEDI_SCORTE()

Dim N As Integer, N1 As Integer

Set RS = New ADODB.Recordset
RS.CursorLocation = adUseClient
RS.Open SQL, CON, adOpenForwardOnly, adLockReadOnly

If Not RS.EOF Then

RS.MoveFirst
RS.Sort = ("REP, IDTIP")

Erase STRDBROWS()
STRDBROWS = RS.GetRows()
RS.Close
Set RS = Nothing

With Me.LVSCORTE

LockWindowUpdate Me.hwnd

.ListItems.Clear

For K = 0 To UBound(STRDBROWS, 2)

If STRDBROWS(9, K) > 0.3 * STRDBROWS(5, K) Then
ICO = 2
N = N + 1
Else
ICO = 1
N1 = N1 + 1
End If

Set ITMX = .ListItems.Add(, , STRDBROWS(8, K), ICO)
ITMX.SmallIcon = ICO
ITMX.SubItems(1) = STRDBROWS(3, K)
ITMX.SubItems(2) = STRDBROWS(0, K)
ITMX.SubItems(3) = STRDBROWS(1, K)
ITMX.SubItems(4) = Format$(STRDBROWS(5, K), "#,##0")
ITMX.SubItems(5) = Format$(STRDBROWS(6, K), "#,##0")
ITMX.SubItems(6) = Format$(STRDBROWS(9, K), "#,##0")
ITMX.SubItems(7) = Format$(Round((STRDBROWS(9, K) / STRDBROWS(5, K)) * 100, 2), "0.00")
ITMX.SubItems(8) = STRDBROWS(7, K)

Next K

Me.LNR5.Caption = Format$(.ListItems.Count, "#,##0")

LockWindowUpdate 0&

End With

Me.LN.Caption = Format$(N1, "#,##0")
Me.LN1.Caption = Format$(N, "#,##0")

End If

End Sub
now i need to add icon in subitem ITMX.SubItems(1) = STRDBROWS(3, K) from imagelist1

possible to use two imagelist?

note:
important for me to have two different imagelist

User avatar
HansV
Administrator
Posts: 78396
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: use two imagelist in listview

Post by HansV »

You can assign different ImageList controls to the ListView's Icons and SmallIcons properties, but you cannot use two different ImageList controls just for the Icons.
So you'll have to add all your icons to the ImageList control that you use for the Icons property, and use the appropriate index numbers.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4344
Joined: 26 Apr 2010, 17:36

Re: use two imagelist in listview

Post by sal21 »

HansV wrote:
09 Mar 2022, 15:15
You can assign different ImageList controls to the ListView's Icons and SmallIcons properties, but you cannot use two different ImageList controls just for the Icons.
So you'll have to add all your icons to the ImageList control that you use for the Icons property, and use the appropriate index numbers.
OK, your suggestion.
nut dont remember how to assign icon to a subitem, in my case: ITMX.SubItems(1)

User avatar
HansV
Administrator
Posts: 78396
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: use two imagelist in listview

Post by HansV »

ITMX.ListSubItems(1).ReportIcon = 37
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 544
Joined: 27 Jun 2021, 10:46

Re: use two imagelist in listview

Post by SpeakEasy »

>how to assign icon to a subitem

The ReportIcon property (although I see Hans got there before me)

>LockWindowUpdate Me.hwnd

Why are you doing this?

User avatar
sal21
PlatinumLounger
Posts: 4344
Joined: 26 Apr 2010, 17:36

Re: use two imagelist in listview

Post by sal21 »

HansV wrote:
09 Mar 2022, 16:06
ITMX.ListSubItems(1).ReportIcon = 37
TKS. Bro