views:

380

answers:

2

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'?

+3  A: 

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;
Jason Heine
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.
James
Great! Glad I could help.
Jason Heine
A: 

how can i refresh checkbox in winform

Adeel