ListIndex Property in ListBox / ComboBox

K

Ken Hutson

Hi Group,

I am reading that the ListIndex property is read only on a form. However,
an example shows this property being set as well. Here is this example.
Which is it?
Thanks.

Ken Hutson
San Antonio, TX

Example

To return the value of the ListIndex property, you can use the following:
Dim l As Long
l = Forms(formname).Controls(controlname).ListIndex


To set the ListIndex property value, you can use the following:
Forms(formname).Controls(controlname).ListIndex = index

Where formname and controlname are the names of the form and list box or
combo box control, respectively, expressed as String values, and index is
the index value of the item.
 
D

Dirk Goldgar

Ken Hutson said:
Hi Group,

I am reading that the ListIndex property is read only on a form.
However, an example shows this property being set as well. Here is
this example. Which is it?
Thanks.

IIRC, you *can* set the ListIndex property, *provided* that the control
has the focus. For a list box, the effect of setting this property
varies depending on whether the list box is single-select or
multi-select. If it's single-select, setting the ListIndex property
also sets the Value property the corresponding list item's bound-column
value.

If your purpose is to set the control to a particular item in its list,
you would do better, as a rule, to set the Value property to the the
appropriate value from the control's ItemData array.
 
K

Ken Hutson

Dirk,

Thanks for your response. Actually trying to synchronize two list boxes
with each other so that the selected items in each list box refer to the
same row in the row source. In this case, project numbers and project
titles. Some users may prefer to choose a project via number... other users
may prefer choosing via project title.

Cheers,
Ken Hutson
San Antonio, TX
 
D

Dirk Goldgar

Ken Hutson said:
Dirk,

Thanks for your response. Actually trying to synchronize two list
boxes with each other so that the selected items in each list box
refer to the same row in the row source. In this case, project
numbers and project titles. Some users may prefer to choose a
project via number... other users may prefer choosing via project
title.

I think I see. But the bound column of each combo box -- visible or
not -- could be the same primary key field in the Projects table, in
which case synchronizing the combo boxes would be as simple as setting
the value of one to the value of the other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top