CheckBox ListView Multiple Selection Problem c# [modified]
-
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
-
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
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[^]
-
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[^]
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 :-))
-
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
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
'sClick
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 forblocks of code
like thisDave
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) -
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
'sClick
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 forblocks of code
like thisDave
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)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...
-
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
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...