Is there a property which one can set on a listbox (on a userform) which would allow one to display items without allowing the user to select one of the items?
Steven Craig Miller
Is there a property which one can set on a listbox (on a userform) which would allow one to display items without allowing the user to select one of the items?
Steven Craig Miller
Last edited by StevenM; 03-26-2012 at 03:31 PM.
My first thought is to just have nothing happen in your code when the listbox is being viewed and a value is selected. You can leave the a list box filled but without programmatic meaning. Just create the list box, fill it, and leave it. Is this what you mean?
If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.
---Keep on Coding in the Free World---
Actually, I was aiming more for the look and feel of a label but with a side scroll-bar. The problem with just leaving "the list box filled but without programmatic meaning" is that the user can still click on items and the item appears selected. I would like to find a way to prohibit the selection of items in the list (if possible).
Steven Craig Miller
Hi StevenM
In the ListBox Properties play with the Enabled and the Locked Properties until you get the effect you want.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please mark your Thread as SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
I've (now) tried changing:
But changing these values (away from the above) also locked the vertical-scrolling scroll-bar on the side so that there was no way to view the other items on the list.![]()
ListBox1.Enabled = True ListBox1.Locked = False
Steven Craig Miller
Hi Steven
Not sure what you're trying to do but try this (change the ListBox name as appropriate)![]()
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Dim i As Long For i = 0 To UserForm1.ListBox1.ListCount - 1 If UserForm1.ListBox1.Selected(i) = True Then UserForm1.ListBox1.Selected(i) = False End If Next i End Sub
Instead of listing the items in a list box, you could put a linefeed delimited string in a TextBox with Multiline = True, Locked=True and ScrollBars = fmScrollBarsVertical
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
MikeRickson wrote:That is almost what I'm wanting. There are two problems.Instead of listing the items in a list box, you could put a linefeed delimited string in a TextBox with Multiline = True, Locked=True and ScrollBars = fmScrollBarsVertical
(1) The vertical scroll bars are not activated until the textbox is clicked. Is there any way to activate them when initializing the userform?
(2) There is a vertical insertion point bar inside the text. The "Locked=True" keeps the user from editing the text. But is there a way to get rid of the insertion point bar too?
Thanks for your help!
Steven Craig Miller
Try code like this
Note that some of the properties specified in the Intialize event could be set at design time rather than in the I. event. Others cannot.![]()
Private Sub UserForm_Initialize() Dim oneCell As Range With tbxDisplay .MultiLine = True: Rem can be set at design time .ScrollBars = fmScrollBarsVertical: Rem design time .EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection: Rem design Rem fill the textbox, crude approach For Each oneCell In Range("A1:A25") tbxDisplay.Text = tbxDisplay.Text & vbCr & CStr(oneCell.Value) Next oneCell .SelStart = 0: Rem run-time only .SelLength = 0: Rem run-time only .Locked = True: Rem run-time only .SetFocus End With SomeOtherControl.SetFocus End Sub
The way to get the scroll bar to appear is to set the focus to the tbxDisplay and then to someOtherControl.
The selection icon cannot be removed. This code puts it out of the way (at the start of the text) but leaves it there. As I was fiddling, I discovered that (as a potential user) the ability to highlight, by selection, part of the contents of the Text Box was a good thing. If your users would feel differently, then KeyDown or MouseUp events could be added to keep the focus away from the text box.
To: mikerickson,
Thanks for your help! It is greatly appreciated!
Per your suggestion, I added:
It is not perfect. I would have been nice if the selection icon could be removed. But all and all, I think I will use this method. Thanks for your help.![]()
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) TextBox1.SelStart = 0 End Sub
Steven Craig Miller
Perhaps
![]()
Private Sub TextBox1_Enter() TextBox1.SelStart = 0 End Sub Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) TextBox1.SelStart = 0 End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case vbKeyTab, vbKeyReturn Case Else KeyCode = 0 End Select End Sub
Thanks! That is even better!
Steven Craig Miller
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks