1

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

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

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

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

会发生什么是根据控件中的最后一项应该是启用或禁用按钮。

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

谢谢

4

1 回答 1

3

如果你想循环你的 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;

希望能帮助到你!

此致!

于 2011-02-02T18:44:19.067 回答