Results 1 to 4 of 4

Thread: Checked ListView Count - NullReferenceException

  1. #1

    Thread Starter
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    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:
    1. CODE:
    2. Private Sub LstVew1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) _
    3. Handles LstVew1.ItemChecked
    4.    If LstVew1.CheckedItems.Count > 1 Then
    5.      lbl1.Text = "Selected items: " & LstVew1.CheckedItems.Count
    6.    Else
    7.      lbl1.Text = "U have 1 or 0 selected item(s)"
    8.    End If
    9. End Sub
    10.  
    11. CODE EXCEPTION:
    12. System.NullReferenceException: Object reference not set to an instance of an object.
    13.    at System.Windows.Forms.ListView.CheckedIndexCollection.get_Count()
    14.    at System.Windows.Forms.ListView.CheckedListViewItemCollection.get_Count()
    15.    at ...
    Thanks in advance
    Last edited by Zeljko; Nov 11th, 2009 at 03:57 PM. Reason: Add that ListView view is Details.
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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?

  3. #3

    Thread Starter
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    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?
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  4. #4

    Thread Starter
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    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?
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


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
  •  



Click Here to Expand Forum to Full Width