[英]How to set repeater control back colour by item index?
I am using a DataRepeater
control to show a popup. 我正在使用
DataRepeater
控件显示弹出窗口。 I am able to set BackColor
of the current item by this code 我可以通过此代码设置当前项目的
BackColor
private void dataRepeater1_CurrentItemIndexChanged(object sender, EventArgs e)
{
dataRepeater1.CurrentItem.BackColor = Color.Red;
}
but I am unable to add BackColor
white for the previous item. 但是我无法为上一项添加
BackColor
white。 Also I want to change the BackColor
of the item form the list I am hovering mouse. 我也想从鼠标悬停的列表中更改项目的
BackColor
。
One way to solve this is to have one more property in your class, maybe called DataRepeater1_PreviousItem
: 解决此问题的一种方法是在您的类中再增加一个属性,也许称为
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.