Listbox Concerns (1 Viewer)

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
I have a 3-column unbound Value list listbox and populating it with .AddItem.
When the Form opens there is a dotted line around the first item . Can this be removed? (I don't need any listbox click event)
When clicking an item this dotted outline fills with black and you can no longer read what the item is.
I wonder also is it possible to justify or center text in the columns?
Thanks.
 

zeroaccess

Active member
Local time
Today, 00:29
Joined
Jan 30, 2020
Messages
671
Is the dotted line the focus? If so, on load, me.somecontrol.setfocus

If you need to make an invisible text box or command button for that purpose, you won't be the only one.

I am unsure about the "fills with black" - can you post a screen shot?
 

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
Yes it is focus, and you can setfocus elsewhere but it comes back if/when you move the listboxes vertical scrollbar.
The 'fills with black' is the highlight for the clicked-on row. It goes to any row but I can't get it to disappear.
Guess you can set the color somehow ? Picture attached
 

Attachments

  • Image1.jpg
    Image1.jpg
    18.4 KB · Views: 106

zeroaccess

Active member
Local time
Today, 00:29
Joined
Jan 30, 2020
Messages
671
Your "theme" associated with your database can change the colors project-wide. While in Design view of a form, Design > Themes. See if that does the trick, and customize from there.

If you find a way to hide the dots for focus, please share.
 

Micron

AWF VIP
Local time
Today, 01:29
Joined
Oct 20, 2018
Messages
3,478
Maybe you have some On Got Focus code for this control? After all, when you move the list, you are giving the control the focus.
you can setfocus elsewhere but it comes back if/when you move the listboxes vertical scrollbar.
 

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
The only way I can find to hide the dots is (as you said) setfocus somewhere else. I used a text box with H & W of 0.
But as Micron explained it comes back so a wasted effort - unless you can move the focus after Mouse Up. However (isn't this typical?) the MouseUp event doesn't fire from the scrollbar. I can't see any scrollbar events that might help. May have to just accept it.
Finding other listbox hassles though. For example leading Spaces are ignored. Any solution for this?
I found a (supposed to work) command Me.Listbox.TextAlign = fmTextAlignCenter but it gives an error here. Perhaps if it needs a reference or something?
Themes show in the Ribbon but is greyed out. Says it affects the whole database (just this, or every one?) Do I need such a major change, if all that's wanted is to set the color of the Highlight?
 

Micron

AWF VIP
Local time
Today, 01:29
Joined
Oct 20, 2018
Messages
3,478
You said you can't see the value, yet I can in your pic. It's not great, but that's because the font is light blue? You didn't answer about code on the control and after reviewing I still don't see what the issue is other than maybe blue doesn't work with black highlight (which you cannot change AFAIK). Also, when I move a scroll bar on a list box, the items don't get selected. That's why I asked if you have a Got Focus event (where you might be selecting a listbox row in code).
You could change the font to black... then it will alter to white font on black highlight.
 

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
Sorry Micron, there's no code in the listbox. The first item acquires the dots when you move the scrollbar, as you explained, as it gets the focus. I've been googling around and found a bit more on this, incl you cannot change the Highlight color (but thanks for confirming). And TextAlign = fmTextAlignCenter may only be in Excel. I did change the font to Red (not much better) but I get now its only able to invert the Fore & back colours thus will always be black on a white background. And it cannot center anything. All very limiting, its a shame.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:29
Joined
Oct 29, 2018
Messages
21,455
Hi. There's no text alignment I am aware of, but you could/should be able to create a function to center the text by padding the text with spaces based on its length and the width of the column.
 

Micron

AWF VIP
Local time
Today, 01:29
Joined
Oct 20, 2018
Messages
3,478
you cannot change the Highlight color
Actually when I hit reply on my last message I forgot that it is possible - in a limited way. The highlight colour is what I'd call the complementary (not complimentary) colour to the backcolor property. The complementary colour of yellow is blue, so if you change the backcolor value to yellow, the highlight will be blue. Whether or not you can influence the shade of blue by varying the shade of yellow, I don't know.

If your list is longer than the control is tall, (which it likely is if you have scroll bar) then you can set the selected item to be somewhere in the list that you can't see.
EDIT - that only seems to work part of the time, and Repainting the form doesn't seem to help. The nth item is selected, but the lines might still be there.
 
Last edited:

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
They seem to have made it as hard as possible to improve... or tweak to ones own requirements.
Does space work for you DBGuy? I did try that - but found leading spaces are ignored. (Access 2010).
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:29
Joined
Oct 29, 2018
Messages
21,455
They seem to have made it as hard as possible to improve... or tweak to ones own requirements.
Does space work for you DBGuy? I did try that - but found leading spaces are ignored. (Access 2010).
Hi. It was just a thought, and I haven't tested it. If regular spaces don't work, you could try "hard" spaces or underscores, maybe?
 

kirkm

Registered User.
Local time
Today, 17:29
Joined
Oct 30, 2008
Messages
1,257
I had to lookup what a hard space was, and was told it's Cntl-Shift Space.
But typing that inside quotes shows nothing. Is there some trick to it ? Yes, unscores would work but probably not improve the appearance.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:29
Joined
Oct 29, 2018
Messages
21,455
I had to lookup what a hard space was, and was told it's Cntl-Shift Space.
But typing that inside quotes shows nothing. Is there some trick to it ? Yes, unscores would work but probably not improve the appearance.
You will probably use VBA to calculate how many spaces to add for the padding. If so, you can use the Chr$() function to generate the hard space. For example, try Chr(255).
 

Users who are viewing this thread

Top Bottom