Solved

Read-Only Combo Box

Posted on 2002-05-03
7
161 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 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 46
Can we place a tooltip on the actual vb6 form 5 41
TT Auto Dashboard 13 92
VB6 - Scroll Mouse wheel on Picturebox 13 44
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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