0

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.

B Z
  • 9,363
  • 16
  • 67
  • 91

3 Answers3

2

This was asked a while ago but just in case anyone else is looking for an answer:

for (int i = 0; i < this.dataRepeater1.ItemCount; i++)
{
    this.dataRepeater1.CurrentItemIndex = i;

    CheckBox checkBox = (CheckBox)
                this.dataRepeater1.CurrentItem.Controls["controlName"];
    bool isChecked = checkBox.Checked;
}

This approach makes it much easier to process/read any related controls on the same repeater item.

Gavin
  • 21
  • 2
0

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
  • 7,673
  • 8
  • 55
  • 56
  • 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 Jan 03 '10 at 18:51
0

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
  • 7,673
  • 8
  • 55
  • 56
  • I tested this and this will not work if you have more items than those which fit my control. This means that controls that are only Visible by scrolling will not appear in `dataRepeater1.Controls`. @peter-gfader, any ideas? – Joel May 08 '13 at 17:52
  • Hmm... Not at the moment. Maybe there is another way to iterate over all controls. I was expecting that to be ".Controls" – Peter Gfader May 10 '13 at 10:45
  • A possible work around: a `List`, `Collection` or something of same sort keeps track of possible changes(such as row selection - I support filtering results, so this strategy works for me) and I hadnle events such as `DataRepeater_ItemClick` ou `DataRepeater_DrawItem` to correctly dsiplay/update elements. When iterating, I iterate on the list/collection instead of `DataRepeater` itself. Not an elegant solution, but it does work. – Joel May 10 '13 at 10:53