Results 1 to 8 of 8
  1. #1
    jpadeutsch is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Nov 2015
    Posts
    8

    List box with alternative colouring for selected item(s)

    Is there any way to modify how the selected item in a listbox is coloured. The standard way is to reverse the foreground and background colours specifed for the listbox? I would prefer to be able to specify different colours specifically for the selected item(s).

  2. #2
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    There was a subject on this last month which I found very interesting.

    https://www.accessforums.net/showthread.php?t=82044

    On the other hand, colours are wonderful, but there are a considerable number of folks out there with varying levels of colour blindness.

    One other possibility, if your list box is not multi-select, is to have one or more text boxes bound to what ever column(s) with either conditional formatting or an after_update event on the list to make changes to the display text boxes.
    --
    Tim

  3. #3
    jpadeutsch is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Nov 2015
    Posts
    8
    Quote Originally Posted by DittoBird View Post
    There was a subject on this last month which I found very interesting.

    https://www.accessforums.net/showthread.php?t=82044

    On the other hand, colours are wonderful, but there are a considerable number of folks out there with varying levels of colour blindness.

    One other possibility, if your list box is not multi-select, is to have one or more text boxes bound to what ever column(s) with either conditional formatting or an after_update event on the list to make changes to the display text boxes.
    --
    Tim
    Thank you. That was indeed very interesting. In fact I already do have a field on the form that does show the selected item. The only reason that I would like to alter how the selected item appears in the listbox itself is that when it reverses to white on black some of the upright strokes in the characters of the text tend to be hard to read. Somehow small patches of non-white seem to appear. Maybe it is a problem with my display.

  4. #4
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by jpadeutsch View Post
    Thank you. That was indeed very interesting. In fact I already do have a field on the form that does show the selected item. The only reason that I would like to alter how the selected item appears in the listbox itself is that when it reverses to white on black some of the upright strokes in the characters of the text tend to be hard to read. Somehow small patches of non-white seem to appear. Maybe it is a problem with my display.
    Forgive me if this sounds ridiculously basic, but have you restarted your machine? That can help.

    If you already have or it doesn't help, is the row source for your list box a simple table or is a query that is possibly complex? Are there a lot of fields in the table or query?

    I can't recall off-hand if there is practical limit for number of rows and fields in a list box but that could be complicating things. You could have the user make a choice or series of choices to limit the results in the list box. Say you have a field for Type in your table or one for colours. You can have a combo box somewhere, probably above the list box that shows the colours or type and then have the query behind the list box reflect that - there's a simple way to do that entering forms!frmYourForm[cboComboCriteria] as a criteria under the Type or Colour. There's a few nuances with that.

    One thing I've always done, which might be useful for you to at least see how many records are in your list box is to add a text box that shows a count of the results in the list box. If you have column heads turned off, then simply put =[lstYourListBox].
    [ListCount]
    as the control source (don't forget the = sign). If you do choose to turn column heads turned on, remember that listcount will include the column head so you'll need to use =IIf([lstTest].
    [ListCount]>1,[lstTest].
    [ListCount]-1,0)
    . That expression will subtract one from the total list count for the total results, or display 0 if the list count is 1, i.e. only the column header.

    I tend to put the totals box in red and a smaller font and have it enabled = No, and Border Style = Transparent, (this is done in the data and format tabs of the Text Box's property sheet). I may make Locked = Yes, too.

    Anyway, that text box will help you see how many results you are getting if you use a criteria combobox or something similar to alter the underlying query of the list box.

    Hope that helps with the messing up of the text box after a selection.
    --
    Tim

  5. #5
    jpadeutsch is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Nov 2015
    Posts
    8
    Quote Originally Posted by DittoBird View Post
    Forgive me if this sounds ridiculously basic, but have you restarted your machine? That can help.

    If you already have or it doesn't help, is the row source for your list box a simple table or is a query that is possibly complex? Are there a lot of fields in the table or query?

    I can't recall off-hand if there is practical limit for number of rows and fields in a list box but that could be complicating things. You could have the user make a choice or series of choices to limit the results in the list box. Say you have a field for Type in your table or one for colours. You can have a combo box somewhere, probably above the list box that shows the colours or type and then have the query behind the list box reflect that - there's a simple way to do that entering forms!frmYourForm[cboComboCriteria] as a criteria under the Type or Colour. There's a few nuances with that.

    One thing I've always done, which might be useful for you to at least see how many records are in your list box is to add a text box that shows a count of the results in the list box. If you have column heads turned off, then simply put =[lstYourListBox].
    [ListCount]
    as the control source (don't forget the = sign). If you do choose to turn column heads turned on, remember that listcount will include the column head so you'll need to use =IIf([lstTest].
    [ListCount]>1,[lstTest].
    [ListCount]-1,0)
    . That expression will subtract one from the total list count for the total results, or display 0 if the list count is 1, i.e. only the column header.

    I tend to put the totals box in red and a smaller font and have it enabled = No, and Border Style = Transparent, (this is done in the data and format tabs of the Text Box's property sheet). I may make Locked = Yes, too.

    Anyway, that text box will help you see how many results you are getting if you use a criteria combobox or something similar to alter the underlying query of the list box.

    Hope that helps with the messing up of the text box after a selection.
    --
    Tim
    Thanks again Tim for your thoughts and efforts. I think that you are making the problem sound much more complicated than it is. There is nothing complicated about the list box. At present there are no more than 200 records and it is never likely to be as many as 400. The problem is there however many or few records there are, even if there is only one record. The list box is not corrupted, it is just that when an item is displayed in white on black rather than black on white it becomes somewhat blurred. It could be my monitor or my vision. So all I would like to do is make it so that the selected item in the list box can have its own foreground and background colours instead of simply swapping the foreground and background colours for the list box. I want the selected item to retain the foreground colour specified for the list box, and to let me give it a different background colour, such as light grey. It should be just enough to show which is the selected item without making a major alteration in the visual effect.
    John

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I think there is a minor/limited thing that you can do regarding the theme and maybe also a property that isn't exposed on the property sheet. Since you're on line now, I've posted this comment but you'll have to stand by while I see if I can recall what it was. It could also be that I'm thinking of a different control type - will take a look.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    OK, if this helps as a start I will look deeper into the options for back color modification if you still want after doing this test. IIRC, the selected (highlighted) result depends on the theme and theme values are the only options you have. I might be able to lighten the highlight but seem to recall that you cannot select whatever highlight you want as an ordinary colour value.
    Note the module level variable at the top: there should be a line that Access inserts below the Dim that separates it from the code. Do not duplicate any Option statement that you might already have. Create a test form with a listbox with some data and add a command button. For the button click event, modify the following to suit your form and control names:
    Code:
    Option Compare Database
    Option Explicit
    Dim lngTheme As Long
    
    Private Sub cmdTheme_Click()
    Dim dblSysNum As Double
    lngTheme = lngTheme + 1
    
    If lngTheme >= 1 And lngTheme <= 49 Then
       dblSysNum = DLookup("SysNum", "tblThemes", "ThemeID = " & lngTheme)
       Me.List75.BackColor = dblSysNum
       Me.Repaint
    Else
       MsgBox "out of range now"
    End If
    
    End Sub
    You also need to link to this spreadsheet as a table, or create an Access table from it.
    SystemColours.zip

    This will enable you to cycle manually through the system values for backcolor. After each button press, select a list item to see the highlight colour you get. Much of the time it will be black, sometimes other colour shades. If none of them interest you, then I'd say you're out of options. At the most, we might be able to alter the shade of the highlight colour. That's the part that remains if you want to pursue this further.

    Note: normally I would not make use of a table PK as data, but I'm going to make an exception here.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by jpadeutsch View Post
    It should be just enough to show which is the selected item without making a major alteration in the visual effect.
    John
    Good stuff, John.

    I hope Micron's post helps, it looks fascinating and I've bookmarked this topic as a result/

    Al the best,
    --
    Tim

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-13-2020, 02:47 PM
  2. Identify the first selected item from a list box
    By jcc285 in forum Programming
    Replies: 5
    Last Post: 04-29-2020, 12:18 PM
  3. Change Font Color of Selected List Box Item
    By buckwheat in forum Access
    Replies: 2
    Last Post: 06-03-2013, 03:46 PM
  4. Replies: 4
    Last Post: 07-27-2011, 09:52 AM
  5. Replies: 1
    Last Post: 11-23-2010, 01:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums