Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NullReferenceException in ListView

NullReferenceException in ListView

Scheduled Pinned Locked Moved C#
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saira Tanwir
    wrote on last edited by
    #1

    Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code

    private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
    {
    attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
    selected_columns.Add(AttributeList.SelectedItem.ToString());
    }//end function

    the exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira

    M T 2 Replies Last reply
    0
    • S Saira Tanwir

      Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code

      private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
      {
      attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
      selected_columns.Add(AttributeList.SelectedItem.ToString());
      }//end function

      the exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Are you talking about System.Windows.Forms.ListView? Cause I can not find a SelectedItem Property there (only SelectedItems which is an Array). All the best, Martin

      S 1 Reply Last reply
      0
      • M Martin 0

        Hello, Are you talking about System.Windows.Forms.ListView? Cause I can not find a SelectedItem Property there (only SelectedItems which is an Array). All the best, Martin

        S Offline
        S Offline
        Saira Tanwir
        wrote on last edited by
        #3

        yes , i 'm talking about System.Windows.Forms.CheckedListBox and there is a property SelectedItem. does this help??

        1 Reply Last reply
        0
        • S Saira Tanwir

          Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code

          private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
          {
          attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
          selected_columns.Add(AttributeList.SelectedItem.ToString());
          }//end function

          the exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira

          T Offline
          T Offline
          tcss
          wrote on last edited by
          #4

          If I picture correctly what you doing, you looping through the listbox and setting the check. This does not imply that thge item being checked is selected. hence the value of the selecteditem is null. examine the selecteditems.count before using the code to see if it is not 0. or set the AttributeList.selecteditem = AttributeList.Items[loopcounter]; AttributeList.selecteditem.Checked = true; but I am not sure if that will fire the event.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups