473,513 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox, ListIndex and ListCount. A BUG???

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
1 8386
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7847
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
4
8480
by: John Guarnieri | last post by:
Hi All, I need some code to drag items in a list box either up or down along with not just the text but with the itemdata too. Can anyone hook me up? TIA John
2
1907
by: Sally | last post by:
In a simple multiselect listbox, what is the code to return an item's index when it is selected? Thanks! Sally
3
2178
by: BVH | last post by:
Hi, I'm currently having a problem with a vb6 project I once wrote that needs to be converted to vb.NET. The problem is as follows : On a form I have a listbox and two commandbuttons. The 2...
3
5737
by: manning_news | last post by:
Using 2003. How do I tell if a selected item on a multi-select listbox is now unselected? If a user unselects an item, I want to prompt them that they've unselected it. No prompt if they're...
3
414
by: Jonnh | last post by:
to use the the property list in the object listbox txtidcodigoencontrado.Value = listbox.List(2) it generates me a compilation error":
1
4010
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
15
17603
by: BinaryGirl23 | last post by:
Hello, I'm sure this is such a simple question I didn't even want to bother posting but for the life of me I just can't get it to work : ( I have a button that toggles "Select All" and "Select...
1
1220
by: jacobevans | last post by:
Hey, I'm trying to make a listbox with a moveable index on a timer. So every second the selected index moves down one and so forth in that fashion. When it reaches the last index it should go back...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.