Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Read-Only Combo Box

Posted on 2002-05-03
7
162 Views
Last Modified: 2010-05-02
How can I make a combo box read only?
0
Comment
Question by:sharon_brindley
7 Comments
 

Expert Comment

by:HobbitHouse
ID: 6988222
under properties, make "enabled" False.  This will work for text boxes, list boxes, combo boxes, bread boxes, safety deposit boxes, post office boxes, etc.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6988249
-set the style to 2-Dropdown list

OR

-set keyascii to 0 into the keypress event
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6988253
readonly combobox:
* either some API (i don't know it...)
* or some vb, which in  the Change and Click event set's the .Listindex value back to the value you want.

CHeers
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6988258
* and of course, you can try to use the .Locked = true property, which will enable the user to see all the values (dropdown), but not choose by clicking or using keyboard...

CHeers
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6988844
If you want full functionality without allowing change:

1) Since the text portion is "useless", as pointed out above, the style should be set to 2-dropdownlist.  Also, the key presses should be disabled:
Private Sub cboXXX_KeyPress(Index As Integer, KeyAscii As Integer)
   KeyAscii = 0
End Sub

2) Since you don't want the user to change the list selection, but could still want to view the choices, you'll need to save the initial state and reset it any time the user inadvertently clicks on a different selection.  To do that, you'll need two code changes:

Private Sub Form_Load()
  Combo1.AddItem "first entry"
  Combo1.AddItem "second entry"
  Combo1.AddItem "third entry"
  Combo1.Tag = "1" ' give an initial value
  Combo1_Click ' set it
End Sub

Private Sub Combo1_Click()
  ' reset it any time the user changes it
  Combo1.ListIndex = Val(Combo1.Tag)
End Sub

Private Sub Combo1_GotFocus()
  ' capture the current setting any time the user goes to it
  Combo1.Tag = CStr(Combo1.ListIndex)
End Sub
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6988850
On further review, angelIII's idea of locked seems to be better.  The difference is that the user cannot click on the dropdown list to close it.
0
 

Author Comment

by:sharon_brindley
ID: 6993351
Setting the style to 2-Dropdown is exactly what I wanted. Setting enabled=false, or locked=true are not suitable as they do not allow the user to select a list item. I actually want full functionality without the user being able to change the items or add more.
Thanks
Sharon
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question