Sunday, May 1, 2011

Can checkboxes be removed from a .NET WinForms ListView at runtime?

Is it possible to remove the checkboxes from a .NET WinForms ListView control at runtime?

The following code appears to have no effect when '.Checkboxes' has initially been set to 'true' and the control has rendered onto a form with checkboxes available for each list view item:

// C#:
testListView.BeginUpdate();  
testListView.Checkboxes = false;  
testListView.EndUpdate();

Is there a method that must be called to enact this change? What is the use of providing the .Checkboxes property when it defaults to 'false' and only has an effect if set to 'true'?

From stackoverflow
  • Hi,

    I just created a sample project using VS 2008 with the following code and it seemed to have worked:

     private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                ListViewItem lvi = new ListViewItem("Test");
                listView1.Items.Add(lvi);
            }
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            listView1.CheckBoxes = false;
        }
    

    the properties for my listview are as follows:

            this.listView1.CheckBoxes = true;
            this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1});
            this.listView1.GridLines = true;
            this.listView1.Location = new System.Drawing.Point(12, 12);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(224, 174);
            this.listView1.TabIndex = 0;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.Details;
    
    James : I just verified that this code works in VS 2005 as well. It appears that there must have been something else in my code causing the ListView to maintain its check boxed state.
    Jason Heine : Great! Glad I could help.
  • how can i refresh checkbox in winform

0 comments:

Post a Comment