禁用 DataRepeater 控件中某些项目的控件

发布于 2024-08-14 20:48:38 字数 475 浏览 3 评论 0原文

我在 C# Winforms 应用程序中使用 Visual Basic Power Pack 中的 DataRepeater 控件。该控件未绑定,在虚拟模式下运行。

我在此控件中显示多个项目。根据某些条件,我想禁用控件中的按钮。

我在数据转发器的 _DrawItem 事件中尝试了以下操作:

private void dataXYZ_DrawItem(object sender, DataRepeaterItemEventArgs e)
{
    int Item=e.DataRepeaterItem.ItemIndex;
    dataXYZ.CurrentItem.Controls["buttonSomething"].Enabled = SomeFunc(Item);
}

发生的情况是根据控件中最后一项的内容启用或禁用按钮。

知道如何逐项控制启用状态吗?

谢谢

I'm using the DataRepeater control from the Visual Basic Power Pack in my C# Winforms application. The control is unbound, operating in VirtualMode.

I'm displaying multiple items in this control. Depending on certain criteria, I want to disable a button in the control.

I've tried the following in the _DrawItem event of the data repeater:

private void dataXYZ_DrawItem(object sender, DataRepeaterItemEventArgs e)
{
    int Item=e.DataRepeaterItem.ItemIndex;
    dataXYZ.CurrentItem.Controls["buttonSomething"].Enabled = SomeFunc(Item);
}

What happens is the button is enabled or disabled based on what the last item in the control should be.

Any idea how I can control enable state on an item by item basis?

Thanks

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

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

发布评论

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

评论(1

太阳男子 2024-08-21 20:48:38

如果你想循环你的 datarepeater 项目,你可以这样做:

            //Store your original index
            int intOldIndex = dataRepeater1.CurrentItemIndex;

            //Loop through datarepeater items and disabled them
            for (int i = 0; i < dataRepeater1.ItemCount; i++)
            {
                //Just change the CurrentItemIndex and the currentItem property will get the element from datarepeater!
                dataRepeater1.CurrentItemIndex = i;
                dataRepeater1.CurrentItem.Enabled = false;

                //You can access some controls in the current item context
                ((TextBox)dataRepeater1.CurrentItem.Controls["txtName"]).Text = "My Name";

                //If your textbox is inside a groupbox, for example, 
                //you'll need search the control because it is inside another
                //control and the textbox will not be accessible
                ((TextBox)dataRepeater1.CurrentItem.Controls.Find("txtName",true).FirstOrDefault()).Text = "My Name";
            }

            //Back your original index
            dataRepeater1.CurrentItemIndex = intIndex;
            dataRepeater1.CurrentItem.Enabled = true;

希望它有帮助!

此致!

If you want to loop your datarepeater items, you can do something like this:

            //Store your original index
            int intOldIndex = dataRepeater1.CurrentItemIndex;

            //Loop through datarepeater items and disabled them
            for (int i = 0; i < dataRepeater1.ItemCount; i++)
            {
                //Just change the CurrentItemIndex and the currentItem property will get the element from datarepeater!
                dataRepeater1.CurrentItemIndex = i;
                dataRepeater1.CurrentItem.Enabled = false;

                //You can access some controls in the current item context
                ((TextBox)dataRepeater1.CurrentItem.Controls["txtName"]).Text = "My Name";

                //If your textbox is inside a groupbox, for example, 
                //you'll need search the control because it is inside another
                //control and the textbox will not be accessible
                ((TextBox)dataRepeater1.CurrentItem.Controls.Find("txtName",true).FirstOrDefault()).Text = "My Name";
            }

            //Back your original index
            dataRepeater1.CurrentItemIndex = intIndex;
            dataRepeater1.CurrentItem.Enabled = true;

Hope it helps!

Best Regards!

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