views:

631

answers:

2

I am using the winform datarepeater control from vb.net power pack.

All of the items on the repeater are readonly except for a checkbox column.

I want to iterate over the items and find out which checkboxes are checked.

I can't find a collection of datarepeateritems on the control and help is scarce.

Thanks for the help.

A: 

Why not just check the datasource of the datarepeater?

E.g. I have a datarepeater bound to a Bindingsource for Persons See button handler

    private void Form1_Load(object sender, EventArgs e)
    {
        List<Person> persons = new List<Person>();
        persons.Add(new Person { Name = "Peter", IsLocal = true });
        persons.Add(new Person { Name = "Sepp", IsLocal = false });
        persons.Add(new Person { Name = "Franz", IsLocal = false });

        personBindingSource.DataSource = persons;
    }


    private void buttonCountCheckBox_Click(object sender, EventArgs e)
    {
        int i = 0;

        foreach (Person singlePerson in personBindingSource)
        {
            if (singlePerson.IsLocal)
            {
                i++;
            }

        }
        Console.WriteLine("DEBUG: checked found: " + i);
    }
Peter Gfader
The checkbox is not bound and is not part of the datasource. It is the first column and is used to check an action e.g. delete all selected.
B Z
see other answer
Peter Gfader
A: 

You could iterate through the Controls list (generated from template)

  1. Rename your checkbox in the datarepeater to "checkBoxUnbound"

  2. Use the below code

    private void button3_Click(object sender, EventArgs e)
    {
        int i = 0;
        CheckBox unboundCheckBox;
        foreach (Control c in dataRepeater1.Controls)
        {
            unboundCheckBox = c.Controls["checkBoxUnbound"] as CheckBox;
            if (unboundCheckBox != null && unboundCheckBox.Checked)
            {
                i++;
            }
        }
    
    
    
    Console.WriteLine("DEBUG: checked found: " + i);
    
    }
Peter Gfader