By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,490 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,490 IT Pros & Developers. It's quick & easy.

ListBox, ListIndex and ListCount. A BUG???

P: n/a
Hi there!

I've got a trouble with these things. What's going on?

1ST STEP: we have ListBox item. Let's call it ListBox1.
We're adding four values to it using AddItem method:
ListBox1.AddItem('a')
ListBox1.AddItem('b')
ListBox1.AddItem('c')
ListBox1.AddItem('d')

At this point ListIndex property is equal to -1 (because we have
clicked nothing yet),
and ListCount, of course, is equal to 4.

2ND STEP: let's click the "c" item.
Now, really, ListIndex=3 as it must be. ListCount unchanged.

3RD STEP: let's delete all of items from ListBox using
RemoveItem:

For X=1 to 4
ListBox1.RemoveItem(0)
Next X

We four times repeated deleting 0th item as far as they shifts each
time when we trying to delete one of the items. But it isn't the
problem.

Note, then HERE ListCount=0 and ListIndex=-1.

4TH STEP: let's populate ListBox with four items again, as at the 1st
step.
NOTE: after that you'll have ListIndex=3 (!) instead of -1. We have NOT
clicked
any item yet, but this property is changed.

What's this????
Why does it happens????

I appreciate any comment on this! Please, drop me a line to
andrew.panin<at>mail.ru

Thanks before, guys!

Feb 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The behavior is related to the ColumnHeads property. To the best of my
recollection, it only manifests if 1. the listbox is unbound and 2. you use
column heads.

MSDN:
The ListCount property setting contains the total number of rows in the
combo box list or list box, as determined by the control's RowSource and
RowSourceType properties. If the control is based on a table or query (the
RowSourceType property is set to Table/Query and the RowSource property is
set to a particular table or query), the ListCount property setting contains
the number of records in the table or query result set. If the RowSourceType
property is set to Value List, the ListCount property setting contains the
number of rows the value list specified in the RowSource property results in
(this depends on the value list and the number of columns in the list box or
combo box list, as set by the ColumnCount property).

If you set the ColumnHeads property to Yes, the row of column headings is
included in the number of rows returned by the ListCount property. For combo
boxes and list boxes based on a table or query, adding column headings adds
an additional row. For combo boxes and list boxes based on a value list,
adding column headings leaves the number of rows unchanged (the first row of
values becomes the column headings).

--
Darryl Kerkeslager
Feb 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.