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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing colour/highlighting/ changing weight of words in list box

Status
Not open for further replies.

SpectacledBear

Programmer
Mar 1, 2005
58
GB
I have a queries menu which is in the form of a dialogue box, showing a list box and buttons. In the list box are my queries. Can I make them or their background change colour on mouse move? thanks!
 
Not with the standard listbox, but you can with the activeX control Microsoft ListView Control
 
Tried it, well I inserted it, but went to properties and couldnt see anything about colours. will i need code to do it?
 
Here's a quick routine I used to populate one of my list boxes for testing purposes. Note that the foreground color of the 2nd item in the list is red and it is ghosted (can't select it).

To see what properties are available to you, dim a dummy variable as ListView (i.e. Dim abc as ListView). Access will then display the properties and methods when you type abc.

In this example, assume that the name of your list box is xlsvFrom. To call the function below, enter this:

FillList xlsvFrom.Object, "From"
Code:
Function FillList(LV As ListView, strPrefix As String) As Boolean
      
    Dim intTotCount As Integer
    Dim intCount1 As Integer
    Dim intCount2 As Integer
    Dim colNew As ColumnHeader
    Dim NewLine As ListItem
    Dim kk As Integer

    LV.ListItems.Clear
    LV.ColumnHeaders.Clear
    
    For intCount1 = 0 To 3
       Set colNew = LV.ColumnHeaders.Add(, , "column" & intCount1)
    Next intCount1
    LV.View = 3    ' Set View property to 'Report'.
    
    For intCount1 = 1 To 10
        
        If (intCount1 = 5) Then kk = 2 Else kk = 1
        Set NewLine = LV.ListItems.Add(, strPrefix & intCount1 & "_Key", strPrefix & intCount1, 1, kk)
        
        For intCount2 = 1 To 3
           NewLine.SubItems(intCount2) = "subfrom1" & intCount2
        Next intCount2
        
        If (intCount1 = 2) Then
           NewLine.ForeColor = 255
           NewLine.Ghosted = True
        End If
    
    Next intCount1

End Function


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top