Results 1 to 4 of 4

Thread: Checked ListView Count - NullReferenceException

Threaded View

  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


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