Link to home
Start Free TrialLog in
Avatar of db_tiger
db_tigerFlag for Germany

asked on

Set ComboBox NOT editable?

I would like to use a ComboBox, where the user cannot edit the text. He should just be able to select an item. Using the 'Lock'-Property locks all the box with no more selection possible.

I think the question is easy, but I didn't find an answer fast. I'll spend 100 points even though it's probably easy and would be very glad to get an answer.

Thanks
db
ASKER CERTIFIED SOLUTION
Avatar of Ruchi
Ruchi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghassan99
ghassan99

Place this in the combobox's keypress event:

Private Sub Combo1_KeyPress(KeyAscii As Integer)
   KeyAscii = 0
End Sub

-Gus
Avatar of db_tiger

ASKER

I like it very much to get fast answers!

Why are those things so complicated?!
Why isn't there a nice property 'ReadOnly' and there we go?

Thanks db


(Change the List1 to Combo1 in your sample code.)
Hy ghassan99,

the other answer was fast and correct, so I already accepted ist. But seems to me, that your code does the same much more easy.
I'll post a question for you and get you some 50 points

thanks db

Btw: Is there a way that, the user can't even highlight or select the contenst of the combobox?
I think the combo1.locked=true
accomplishes that.  Or u want something else?

-Gus
No, it doesn't.
I would like to allow the user to change the contents by selecting an item as it is possible with yours solutions.
But I would like it - for reason of asethtics - that he could'nt even enter the textbox-part of the combobox (which gets highlighted and shows the blinking cursor, when enterd - (even though the cursor can't be moved).

I think HTML-ComboBoxes behave like that. Not important, but nice to have.
How are you doing with the combo box thing? Please let me know...
Hy Ruchi,

read my last comment: that's what I'm still seeking for.

Your API-Declarations are great, but ghassans99 hint does pretty the same thing with less code.
So if I won't get in problems, I'll take of course the short solution. But thanks anyway for your solution. It's correct and you gave me a possible solution fast.

db
Hy again Ruchi,

I apologize: Your solution is superior! gansen99 idea lacks one major point - the user is able to delete the contents of the textbox-part by pressing <delete> - that is not acceptable, so your solution wins.
The points you got anyway.

by db
Db,

Do you want to know how to "allow the user to change the contents by selecting an item as it iss possible with my solutions?" If so, please let me know... Or did you work? (I skimmed your comments because I am kind of in a hurry)

Thanks. :)
No I'm fine with that.

I would appreciate one further point: I would like it, if the user wasn't even able to enter the TextBox-Part of the comboBox with the cursor.
Your solution is fine, but if the user clicks in the combo-Box the text gets highlighted, seems to be editable and the cursor blinks.
 It would be nicer, to avoid this behaviour, because it's kind of misleading: The TextBox seems to be editable but isn't.

Don't worry Ruchi, if you're in troublke with some other work. I'm already fine with your solution.
It's just a small thing, which would be nice to have.

db

db_tiger,
u can disable all kind of keyboard clicks like del, ins...even ctrl+c to copy or ctrl+x to cut, just place this in the keydown event of the combo box:
KeyCode = 0
very simple!

-Gus
I'm going to work on a small thing for you.. by tonight or tomorrow.

:)
I got what u want db, just change the style of the combo box to 2 or 'Dropdown list' u dont even need to disable keyboard strokes, coz in that style u cant change the values.

-Gus
ghassan99

First comment: That's not true: Select the Box, the text get highighted, try to type some character - does not work - try to type 'Delete' - the entries disappear.

ghassan99

Second comment: Now you really got, what I want: That is even more simple than both solution before.
I'm a little ashamed, that I did not found it by myself before, but now you made the work for me.
I thought that the MS-Box should have an optioin like that, because it's too usual to be more complicated.

Thanks again, db

ruchi:

Hope you read the comments before spending time on 'the little thing'. Thanks again for the API-declarations, which did the job - but of course using one simple property is the way, it should be done - if possible.

Thank you, db


Glad it worked db.
But again u didnt probably got me, yes the delete will work, but place an additional code of one line in the KEYDOWN event not KEYPRESS...
keycode=0
and also keep the orginal code in the KEYPRESS event
keyascii=0
then there is nothing u can type anymore, not even the delete.

-Gus
Oh you are right Gus, I didn't read that - KeyDOWN supplementaire to KeyPRESS: this way it does the same as ruchi API-calls.
But the correct setting of the appropriate property ('style') is the best way.

Thanks again, lots of comments on at least a simple question :-)

db
I agree with Gus's comments on drop-down list - 2. With the drop-down list, the user cannot type an alternative item. I'm glad it worked fine for you.
:)
All the best,
Ruchi