通过 DataRepeater 进行迭代 (VB.Net PowerPack)

发布于 2024-07-14 04:30:08 字数 176 浏览 9 评论 0原文

我正在使用 vb.net power pack 中的 winform datarepeater 控件。

除复选框列外,转发器上的所有项目都是只读的。

我想迭代这些项目并找出选中了哪些复选框。

我在控件上找不到数据重复项目的集合,并且帮助很少。

谢谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

策马西风 2024-07-21 04:30:08

不久前就有人问过这个问题,但以防万一其他人正在寻找答案:

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 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.

软的没边 2024-07-21 04:30:08

您可以遍历控件列表(从模板生成)

  1. 将数据重复器中的复选框重命名为“checkBoxUnbound”

  2. 使用以下代码

    private void button3_Click(对象发送者,EventArgs e) 
      { 
          整数 i = 0; 
          复选框 unboundCheckBox; 
          foreach(dataRepeater1.Controls 中的 Control c) 
          { 
              unboundCheckBox = c.Controls["checkBoxUnbound"] as CheckBox; 
              if (unboundCheckBox != null && unboundCheckBox.Checked) 
              { 
                  我++; 
              } 
          } 
    
          Console.WriteLine("调试:检查发现:" + i); 
    
      } 
      

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);
    
    }
    
欢你一世 2024-07-21 04:30:08

为什么不直接检查 datarepeater 的数据源呢?

例如,我有一个绑定到 Persons 的 Bindingsource 的数据中继器
请参阅按钮处理程序

    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);
    }

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文