1

DataRepeaterC# 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 に答える