Reputation: 9453
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.
Upvotes: 0
Views: 3988
Reputation: 21
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.
Upvotes: 2
Reputation: 7741
You could iterate through the Controls list (generated from template)
Rename your checkbox in the datarepeater to "checkBoxUnbound"
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);
}
Upvotes: 0
Reputation: 7741
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);
}
Upvotes: 0