|
-
Nov 11th, 2009, 03:16 PM
#1
Thread Starter
Hyperactive Member
Checked ListView Count - NullReferenceException
Win XP, VS 2008, .NET 2.0
When I use Count property to count checked items in ListView (set to detail view with check boxes), sometimes i get NullReferenceException on count part. Sometimes I get it but sometimes I don't get it... It's very randomly and I can not reproduce it always?!? It just happens sometimes 
Can somebody tell me why or point me a lil bit?
VB.Net Code:
CODE: Private Sub LstVew1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) _ Handles LstVew1.ItemChecked If LstVew1.CheckedItems.Count > 1 Then lbl1.Text = "Selected items: " & LstVew1.CheckedItems.Count Else lbl1.Text = "U have 1 or 0 selected item(s)" End If End Sub CODE EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.ListView.CheckedIndexCollection.get_Count() at System.Windows.Forms.ListView.CheckedListViewItemCollection.get_Count() at ...
Thanks in advance
Last edited by Zeljko; Nov 11th, 2009 at 03:57 PM.
Reason: Add that ListView view is Details.
-
Nov 11th, 2009, 10:45 PM
#2
Re: Checked ListView Count - NullReferenceException
Try and figure out what is null. Is it the listview or is it the checked collection?
Do you ever call .Dispose on the listview?
-
Nov 12th, 2009, 02:29 AM
#3
Thread Starter
Hyperactive Member
Re: Checked ListView Count - NullReferenceException
The problem is that I really don't know for sure on which part is error exactly while this never happened in debuger (in vs environment). This happens on rare occasions (like 1 per week) and in exe file on some machine... Never on my machine 
- I don't call dispose for list view. Do u think that not disposing it cause souch problems? I can not dispose it while I use it when is form opened. ListView is filled with data and when using it, some data gets checked by user some gets unchecked, so I need it and i cant dispose it.
Yesterday evening I heard some guys talking about that they get exactly the same error on listview.checked.count part and they suspect .net 2 framework bug. Hmmm. If that is the case can i count it in another way... more safer way?
-
Nov 12th, 2009, 03:22 PM
#4
Thread Starter
Hyperactive Member
Re: Checked ListView Count - NullReferenceException
New updates on this bug.
I isolated this bug to users that have installed on their computers maximum original .NET framework 2 with no service pack and no .net 3 and no .net 3.5. Strange that affects only users with NET 1/1.1 and NET 2. Other users seems to be fine...
If that is the case, I am now interested in finding another way to count checked items in listview? Is there?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|