如何按项目索引设置转发器控制颜色?

时间:2015-09-25 11:30:25

标签: c# .net winforms powerpacks

我使用DataRepeater控件来显示弹出窗口。我可以通过此代码

设置当前项目的BackColor
private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
{
   dataRepeater1.CurrentItem.BackColor = Color.Red;
}

但我无法为上一项添加BackColor白色。此外,我想从我悬停鼠标的列表中更改项目的BackColor

1 个答案:

答案 0 :(得分:0)

解决此问题的一种方法是在班级中再增加一个属性,可能称为DataRepeater1_PreviousItem

class YourClass
{
    DataRepeaterItem DataRepeater1_PreviousItem { get; set; }

    // ... some other code

    private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
    {
        if (DataRepeater1_PreviousItem != null)
            DataRepeater1_PreviousItem.BackColor = Color.White;

        dataRepeater1.CurrentItem.BackColor = Color.Red;

        DataRepeater1_PreviousItem = dataRepeater1.CurrentItem;
    }
}