how to highlight and set color and font for selected ListBox item (1 Viewer)

eugzl

Member
Local time
Today, 07:29
Joined
Oct 26, 2021
Messages
125
Hi All.
I tried to change color and font for selected ListBox item. For that I used this code, but unfortunately it don't give me result.
Code:
Private Sub YourListBoxName_Click()
    Dim i As Integer
    
    For i = 0 To Me.YourListBoxName.ListCount - 1
        If Me.YourListBoxName.Selected(i) = True Then
            Me.YourListBoxName.ItemData(i) = 1
            Me.YourListBoxName.ItemData(i) = RGB(255, 255, 255) ' set font color to white
            Me.YourListBoxName.ItemData(i) = RGB(0, 0, 255) ' set background color to blue
            Me.YourListBoxName.ItemData(i) = True ' set font to bold
        Else
            Me.YourListBoxName.ItemData(i) = 0
            Me.YourListBoxName.ItemData(i) = RGB(0, 0, 0) ' set font color to black
            Me.YourListBoxName.ItemData(i) = RGB(255, 255, 255) ' set background color to white
            Me.YourListBoxName.ItemData(i) = False ' set font to regular
        End If
    Next i
End Sub

How to fix the problem? Thanks
 

CJ_London

Super Moderator
Staff member
Local time
Today, 12:29
Joined
Feb 19, 2013
Messages
16,613
List boxes don’t have that level of formatting functionality, you would need to use a subform instead
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:29
Joined
May 21, 2018
Messages
8,529
The ItemData property returns the data in the bound column for the specified row in a list box. Read-only Variant.
 
Last edited:

Users who are viewing this thread

Top Bottom