C# 禁用DataRepeater控件中某些项的控件

C# 禁用DataRepeater控件中某些项的控件,c#,datarepeater,virtualmode,C#,Datarepeater,Virtualmode,我正在使用C#Winforms应用程序中Visual Basic Power Pack中的DataRepeater控件。控件未绑定,在VirtualMode中运行 我正在该控件中显示多个项目。根据某些条件,我想禁用控件中的按钮 我在data repeater的_DrawItem事件中尝试了以下操作: private void dataXYZ_DrawItem(object sender, DataRepeaterItemEventArgs e) { int Item=e.DataRepe

我正在使用C#Winforms应用程序中Visual Basic Power Pack中的
DataRepeater
控件。控件未绑定,在VirtualMode中运行

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

我在data repeater的_DrawItem事件中尝试了以下操作:

private void dataXYZ_DrawItem(object sender, DataRepeaterItemEventArgs e)
{
    int Item=e.DataRepeaterItem.ItemIndex;
    dataXYZ.CurrentItem.Controls["buttonSomething"].Enabled = SomeFunc(Item);
}
发生的情况是,根据控件中最后一项的内容启用或禁用按钮

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


谢谢

如果要循环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;
//存储原始索引
int intOldIndex=dataRepeater1.CurrentItemIndex;
//循环遍历datarepeater项并禁用它们
对于(int i=0;i
希望有帮助

致以最良好的祝愿