Combobox (Dropdown List: Style=2) 
Author Message
 Combobox (Dropdown List: Style=2)

I have a question regarding a dropdown list.

I do the following

List1.Additem ""
List1.Additem "1"
List1.Additem "2"
List1.Additem "3"
List1.Text = "2"

and it works fine.  But if I try:

List1.Text = ""

then I get the Text property is read only error.  The empty string is
in the list, why can't the lists text property be set to it?



Sun, 09 Jan 2005 07:26:35 GMT  
 Combobox (Dropdown List: Style=2)

Quote:
>I have a question regarding a dropdown list.

>I do the following

>List1.Additem ""
>List1.Additem "1"
>List1.Additem "2"
>List1.Additem "3"
>List1.Text = "2"

>and it works fine.  But if I try:

>List1.Text = ""

>then I get the Text property is read only error.  The empty string is
>in the list, why can't the lists text property be set to it?

The text property is used for lookups and retrieving the current text.
It will not accept an empty string as that would be somewhat silly to
search for in a control like the Combo box. :-)  
Use a single space instead, if you have to.

Regards, Frank



Sun, 09 Jan 2005 07:57:25 GMT  
 Combobox (Dropdown List: Style=2)
Setting the text property on a style-2 combo will lead to errors if the list
does not contain an exact match to the string assigned to the text property.
For all intents and purposes, you consider setting the text property as poor
practice with a style-2 combo.

To clear the selection with a style-2 combo (or list for that matter), set
the listindex property to -1.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


| I have a question regarding a dropdown list.
|
| I do the following
|
| List1.Additem ""
| List1.Additem "1"
| List1.Additem "2"
| List1.Additem "3"
| List1.Text = "2"
|
| and it works fine.  But if I try:
|
| List1.Text = ""
|
| then I get the Text property is read only error.  The empty string is
| in the list, why can't the lists text property be set to it?



Sun, 09 Jan 2005 11:18:31 GMT  
 Combobox (Dropdown List: Style=2)
The combobox (dropdown list style) in VBA allows you to add "" to the
list and set it's text property to it.... it is too bad it can't be
done on the combobox in VB....
Quote:

> Setting the text property on a style-2 combo will lead to errors if the list
> does not contain an exact match to the string assigned to the text property.
> For all intents and purposes, you consider setting the text property as poor
> practice with a style-2 combo.

> To clear the selection with a style-2 combo (or list for that matter), set
> the listindex property to -1.

> --

> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.



> | I have a question regarding a dropdown list.
> |
> | I do the following
> |
> | List1.Additem ""
> | List1.Additem "1"
> | List1.Additem "2"
> | List1.Additem "3"
> | List1.Text = "2"
> |
> | and it works fine.  But if I try:
> |
> | List1.Text = ""
> |
> | then I get the Text property is read only error.  The empty string is
> | in the list, why can't the lists text property be set to it?



Mon, 10 Jan 2005 01:30:04 GMT  
 Combobox (Dropdown List: Style=2)
| The combobox (dropdown list style) in VBA allows you to add "" to the
| list and set it's text property to it.... it is too bad it can't be
| done on the combobox in VB....

Well, I don't know about that. Personally I find it easier to manipulate the
list index than dink around with the text property, regardless of the
combo's style (in VB).

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


| The combobox (dropdown list style) in VBA allows you to add "" to the
| list and set it's text property to it.... it is too bad it can't be
| done on the combobox in VB....
|


| > Setting the text property on a style-2 combo will lead to errors if the
list
| > does not contain an exact match to the string assigned to the text
property.
| > For all intents and purposes, you consider setting the text property as
poor
| > practice with a style-2 combo.
| >
| > To clear the selection with a style-2 combo (or list for that matter),
set
| > the listindex property to -1.
| >
| >
| > --
| >
| > Randy Birch
| > MVP Visual Basic
| > http://www.mvps.org/vbnet/
| > Please respond only to the newsgroups so all can benefit.
| >
| >


| > | I have a question regarding a dropdown list.
| > |
| > | I do the following
| > |
| > | List1.Additem ""
| > | List1.Additem "1"
| > | List1.Additem "2"
| > | List1.Additem "3"
| > | List1.Text = "2"
| > |
| > | and it works fine.  But if I try:
| > |
| > | List1.Text = ""
| > |
| > | then I get the Text property is read only error.  The empty string is
| > | in the list, why can't the lists text property be set to it?



Mon, 10 Jan 2005 09:21:32 GMT  
 Combobox (Dropdown List: Style=2)

Quote:

>| The combobox (dropdown list style) in VBA allows you to add "" to the
>| list and set it's text property to it.... it is too bad it can't be
>| done on the combobox in VB....

>Well, I don't know about that. Personally I find it easier to manipulate the
>list index than dink around with the text property, regardless of the
>combo's style (in VB).

Actually, i find the text property is handy at times and that error it
throws is trappable.
What i wouldn't do is to add an empty string to a combo or a listbox.

Regards, Frank



Mon, 10 Jan 2005 10:06:59 GMT  
 Combobox (Dropdown List: Style=2)
Well don't I fell stupid.  I have been tring to find a clean way to do
that for YEARS!!!!
Quote:

> Setting the text property on a style-2 combo will lead to errors if the list
> does not contain an exact match to the string assigned to the text property.
> For all intents and purposes, you consider setting the text property as poor
> practice with a style-2 combo.

> To clear the selection with a style-2 combo (or list for that matter), set
> the listindex property to -1.

> --

> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.



> | I have a question regarding a dropdown list.
> |
> | I do the following
> |
> | List1.Additem ""
> | List1.Additem "1"
> | List1.Additem "2"
> | List1.Additem "3"
> | List1.Text = "2"
> |
> | and it works fine.  But if I try:
> |
> | List1.Text = ""
> |
> | then I get the Text property is read only error.  The empty string is
> | in the list, why can't the lists text property be set to it?



Tue, 11 Jan 2005 07:52:56 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. ComboBox - Dropdown List Style

2. ComboBox with Style set as DropDown List: Problem.

3. Checkmark in Dropdown List Style Combobox

4. VB6: ComboBox with .Style Dropdown List not maintaining .ListIndex setting

5. Dynamically creating combobox with Style=2 - Dropdown List?

6. ComboBox (Style -> Dropdown List) Change() event

7. ComboBox - Style 2 - Dropdown List

8. ComboBox: Style(2 - DropDown List), change value?

9. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

10. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

11. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

12. Key Press in ComboBox when style is DropDown is not working

 

 
Powered by phpBB® Forum Software