Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Set ListBox.Value

Status
Not open for further replies.

f64

Technical User
May 23, 2003
24
US
For a ListBox, is setting the ListIndex property the same as setting the value property?

Given a ListBox already populated with;
AAAAA
BBBBB
CCCCC
DDDDD

ListBox.value = "BBBBB" does not set the value but

ListBox.ListIndex = 1 does select BBBBB

Does setting the value also set the ListIndex #? Is it possible to set the selection by setting the value equal to a member of the list?
 
Yes.

Think of the value as read-only. You insert a list into a listbox. Each item in the list is a number in the ListIndex.

AAAAA = 0
BBBBB = 1
CCCCC = 2
DDDDD = 3

You do not, in fact "set" the value of the listbox - except when you populate it in the first place. Once populated, well, the values ARE set. They are referenced by the ListIndex. Their values are fixed to the AddItem entry.

Which is why

MsgBox ListBox1.Value
ListBox1.Value = "Hello"

will display the value, but will fail on setting it. Listbox.Value can not be set directly...at least not like that.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top