Solved

Read-Only Combo Box

Posted on 2002-05-03
7
158 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

11 Experts available now in Live!

Get 1:1 Help Now