Click here to Skip to main content
16,020,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
One of our VB6 project form is having a combo box. It's style is set to 2(Drop-down List Box).

When style is set to 2, its Text property becomes read-only. We cannot assign value to it.

But in our project some one has written code to assign string to Text property, and is working fine.

combobox1.Text = "Something" 'working


If i create a same kind of combo box with same properties, i am not able to assign string to text property. I am getting error runtime error 383 : text property is read-only

combobox2.Text = "Something" 'Not working


Can anyone help me understanding what i am missing

What I have tried:

I tried adding same control with same properties set to my new control as that of old one.
Posted
Updated 21-Sep-16 2:03am

1 solution

With VB6 combo boxes set to 'Drop-down List Box' you can "assign" a value to the Text property if the combobox list of items contains exactly that text. It is actually the equivalent of programmatically selecting an existing entry.

If it is not working for your combobox2 then you have not yet added the text "Something" to that combobox OR the code is running before the list is fully populated (e.g. in a Form load event).

Note the "exactly" ... if an existing item text begins with "Something" but is followed by other characters (including spaces) then it will not work. It is also case sensitive.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900