ListView headache - null items?

ListView headache - null items?

Post by rogercnorr » Tue, 01 May 2007 23:39:12

I'm searching for an explanation of some odd ListView behavior (odd to
me at least). My ListView is telling me that several of the items in
its collection are null, but I don't see how that's possible.

In the constructor of my class I add several objects to the list view,
like such:

ListViewItem item = new ListViewItem( itemLabel );
nodeItem.Checked = itemChecked;
nodeItem.ImageIndex = itemImage;
_listView.Items.Add( item );

All of this goes on inside of a BeginUpdate(), EndUpdate() block. If
I set a breakpoint after the EndUpdate() is called, an inspection of
the ListView reveals that all of the items have been added correctly
(i.e. there are no null objects in the ListView's collection).

However, after the constructor of my form finishes, the ListView is
firing an ItemChecked event. In this event handler I have something
like the following:

foreach( ListViewItem item in _listView.Items )
if( item.Checked ) {
// Do something

The odd behavior is that at this point the ListView now contains a
bunch of null objects (except for the first object). The above code
throws a null reference when it gets past the 1st object in the list.

Can anyone explain this behavior? I'm 100% certain that my code is
not manually removing items from the list.

1. Copy ListView Items to a ListView on another form

2. ListView Headache

I have a ListView with a list of images.
The images show sequentially starting with the image clicked (images above
this one do not show).
This is all fine.
However, if I click a image near the top then shift-click an image several
rows below, the _ItemClick event fires for each row within the selection. I
never realized this happened until now so I can see now why some old apps I
wrote are slow.

Unfortuantely this renders each image multiple times and is really sloooow.

Is there a best way to avoid or short circuit the _ItemClick from firing for
all the rows in a shift-click scenario. It is not refiring from within the
event so I cannot set a flag in there to exit.
I need to look at ctrl-click now too.

I see several possibilities for a solution that I have not yet coded but was
wondering is here was some sendmessage or something that is more to the point.

(1) can I capture mouse down (if it occurs before _ItemClick) and flag if
shift is true?
(2) maybe do something with the
ByVal item As MSComctlLib.ListItem
in the _ItemClick line

3. Is this possible - dragging listview item to another item

4. Clicking a listview item and changing the Item color or Row color

5. custom listview loses item color when no item is selected

6. How to set detail item counter to null when detail record is null?

7. KLAcquireInitialTickets(NULL, NULL, NULL, NULL) returns klParameterErr (19276) on Mac OS X 10.6.3

8. WinHttpDownloadFileToMemory(szURLDest, NULL, 0, NULL, NULL, NULL, &downloadBuffer) failed with hr=0x80190194

9. WinHttpDownloadFileToMemory(szURLDest, NULL, 0, NULL, NULL, NULL,

10. generic headache imitrex migraine imitrex headaches cluster cause does drowsiness imitrex

11. Vista Installation Issues, Headache after Headache

12. SQL headache - no longer a headache :-)

13. ListView.EditItem returns null for EditIndex of 0

14. Null reference Exception in ListView.InsertItem

15. VB listView and Null values