Solved

Read-Only Combo Box

Posted on 2002-05-03
7
159 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 69

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 142

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now