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. CheckBox ListView Multiple Selection Problem c# [modified]

CheckBox ListView Multiple Selection Problem c# [modified]

Scheduled Pinned Locked Moved C#
helpcsharpquestion
6 Posts 3 Posters 2 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.
  • V Offline
    V Offline
    varunpandeyengg
    wrote on last edited by
    #1

    I am trying to develop an application with list view having CheckBoxes and Multiple Selection property as TRUE. Single Selection works perfectly. But when I try Multiple selection, check box of all the currently selected rows get changed on every selection (and sets to not of the check value of the new selection) Am I missing any event that I need to handle??? Please help me guys!!! Thanks in advance... Although I haven't handle any event, I am still giving the code (I think it'll be irrelevant) //////////////// listView Properties/////////////////////////////////// this.listView.CheckBoxes = true; this.listView.FullRowSelect = true; this.listView.HideSelection = false; this.listView.UseCompatibleStateImageBehavior = false; this.listView.View = System.Windows.Forms.View.Details; //////////////////////////////////////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); listView.Columns.Add("One", 100, HorizontalAlignment.Left); listView.Columns.Add("Two", 100, HorizontalAlignment.Left); listView.Columns.Add("Three", 100, HorizontalAlignment.Left); listView.Columns.Add("Four", 100, HorizontalAlignment.Left); for(int i = 0; i < 50; i++) { ListViewItem item = new ListViewItem(); item.Checked = true; item.SubItems.Add("Garbage1"); item.SubItems.Add("Garbage2"); item.SubItems.Add("Garbage3"); listView.Items.Add(item); } } } IMP:- This is happening only when I am clicking column other than the first one for selection...

    modified on Saturday, July 9, 2011 5:39 AM

    S D V 3 Replies Last reply
    0
    • V varunpandeyengg

      I am trying to develop an application with list view having CheckBoxes and Multiple Selection property as TRUE. Single Selection works perfectly. But when I try Multiple selection, check box of all the currently selected rows get changed on every selection (and sets to not of the check value of the new selection) Am I missing any event that I need to handle??? Please help me guys!!! Thanks in advance... Although I haven't handle any event, I am still giving the code (I think it'll be irrelevant) //////////////// listView Properties/////////////////////////////////// this.listView.CheckBoxes = true; this.listView.FullRowSelect = true; this.listView.HideSelection = false; this.listView.UseCompatibleStateImageBehavior = false; this.listView.View = System.Windows.Forms.View.Details; //////////////////////////////////////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); listView.Columns.Add("One", 100, HorizontalAlignment.Left); listView.Columns.Add("Two", 100, HorizontalAlignment.Left); listView.Columns.Add("Three", 100, HorizontalAlignment.Left); listView.Columns.Add("Four", 100, HorizontalAlignment.Left); for(int i = 0; i < 50; i++) { ListViewItem item = new ListViewItem(); item.Checked = true; item.SubItems.Add("Garbage1"); item.SubItems.Add("Garbage2"); item.SubItems.Add("Garbage3"); listView.Items.Add(item); } } } IMP:- This is happening only when I am clicking column other than the first one for selection...

      modified on Saturday, July 9, 2011 5:39 AM

      S Offline
      S Offline
      Shahriar Iqbal Chowdhury Galib
      wrote on last edited by
      #2

      hi, You are missing

      this.ListView1.MultiSelect = true;

      Please go through msdn http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.multiselect.aspx#Y162[^]

      V 1 Reply Last reply
      0
      • S Shahriar Iqbal Chowdhury Galib

        hi, You are missing

        this.ListView1.MultiSelect = true;

        Please go through msdn http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.multiselect.aspx#Y162[^]

        V Offline
        V Offline
        varunpandeyengg
        wrote on last edited by
        #3

        Thanx for the reply... No Multiple Selection property is TRUE... It hardly takes 5 minutes to make this sample... Just Try it... I think this is the default behavior... Am I missing any event that I need to handle??? Please help me... Getting stuck on such a puny issue :-| Full points for anybody who helps... (Silly Bargain :-))

        1 Reply Last reply
        0
        • V varunpandeyengg

          I am trying to develop an application with list view having CheckBoxes and Multiple Selection property as TRUE. Single Selection works perfectly. But when I try Multiple selection, check box of all the currently selected rows get changed on every selection (and sets to not of the check value of the new selection) Am I missing any event that I need to handle??? Please help me guys!!! Thanks in advance... Although I haven't handle any event, I am still giving the code (I think it'll be irrelevant) //////////////// listView Properties/////////////////////////////////// this.listView.CheckBoxes = true; this.listView.FullRowSelect = true; this.listView.HideSelection = false; this.listView.UseCompatibleStateImageBehavior = false; this.listView.View = System.Windows.Forms.View.Details; //////////////////////////////////////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); listView.Columns.Add("One", 100, HorizontalAlignment.Left); listView.Columns.Add("Two", 100, HorizontalAlignment.Left); listView.Columns.Add("Three", 100, HorizontalAlignment.Left); listView.Columns.Add("Four", 100, HorizontalAlignment.Left); for(int i = 0; i < 50; i++) { ListViewItem item = new ListViewItem(); item.Checked = true; item.SubItems.Add("Garbage1"); item.SubItems.Add("Garbage2"); item.SubItems.Add("Garbage3"); listView.Items.Add(item); } } } IMP:- This is happening only when I am clicking column other than the first one for selection...

          modified on Saturday, July 9, 2011 5:39 AM

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          This is the correct behaviour. Selecting an item should not change it's checked state. If it did then the check box would be useless as it would only be a reflection of the selected state which is already indicated by the focus rectangle. To get the behaviour you desire, handle the ListView's Click event:

          private void listView_MouseClick(object sender, MouseEventArgs e)
          {
          foreach (ListViewItem item in listView.Items)
          item.Checked = item.Selected;
          }

          By the way, the inline code widget is for code written inline like this. The code block widget is for

          blocks of code
          like this

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          V 1 Reply Last reply
          0
          • D DaveyM69

            This is the correct behaviour. Selecting an item should not change it's checked state. If it did then the check box would be useless as it would only be a reflection of the selected state which is already indicated by the focus rectangle. To get the behaviour you desire, handle the ListView's Click event:

            private void listView_MouseClick(object sender, MouseEventArgs e)
            {
            foreach (ListViewItem item in listView.Items)
            item.Checked = item.Selected;
            }

            By the way, the inline code widget is for code written inline like this. The code block widget is for

            blocks of code
            like this

            Dave
            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            V Offline
            V Offline
            varunpandeyengg
            wrote on last edited by
            #5

            Thanks for replying. I know that it is the default behavior of list view with Check box but I need to change that. The solution you gave fails if I select some unchecked Item...

            1 Reply Last reply
            0
            • V varunpandeyengg

              I am trying to develop an application with list view having CheckBoxes and Multiple Selection property as TRUE. Single Selection works perfectly. But when I try Multiple selection, check box of all the currently selected rows get changed on every selection (and sets to not of the check value of the new selection) Am I missing any event that I need to handle??? Please help me guys!!! Thanks in advance... Although I haven't handle any event, I am still giving the code (I think it'll be irrelevant) //////////////// listView Properties/////////////////////////////////// this.listView.CheckBoxes = true; this.listView.FullRowSelect = true; this.listView.HideSelection = false; this.listView.UseCompatibleStateImageBehavior = false; this.listView.View = System.Windows.Forms.View.Details; //////////////////////////////////////////////////////////////////////////// public partial class Form1 : Form { public Form1() { InitializeComponent(); listView.Columns.Add("One", 100, HorizontalAlignment.Left); listView.Columns.Add("Two", 100, HorizontalAlignment.Left); listView.Columns.Add("Three", 100, HorizontalAlignment.Left); listView.Columns.Add("Four", 100, HorizontalAlignment.Left); for(int i = 0; i < 50; i++) { ListViewItem item = new ListViewItem(); item.Checked = true; item.SubItems.Add("Garbage1"); item.SubItems.Add("Garbage2"); item.SubItems.Add("Garbage3"); listView.Items.Add(item); } } } IMP:- This is happening only when I am clicking column other than the first one for selection...

              modified on Saturday, July 9, 2011 5:39 AM

              V Offline
              V Offline
              varunpandeyengg
              wrote on last edited by
              #6

              I guess Multiple Selection Property and Check Box property are the for same purpose. To eliminate multiple selection by CTRL Key, we can also use CheckBoxes property. Using both the properties simultaneously conflicts behaviorally. It was my clients requirement to ave Enable /Disable feature in the list itself. Indeed, it wasn't the best way to design by using checked property of ListView for any other purpose. After a long discussion with my team members, we have come to a conclusion that it is better to eliminate Multiple Selection feature from the product. :-| Although, I have a possible solution- Store the state of all the items just before every click and re-apply it after the click. But this might create trouble only if no. of items exceed a few thousand. Anyways, I am still open for better (optimized) solution. Thanks everybody...

              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