我使用以下内容替换转发器中的某些数据 -
BindingSource bindingSource5 = new BindingSource();
bindingSource5.DataSource = BookingManager.GetBookingDaysForDayWithBookingFields(DateTime.Now.AddDays(+4));
lbSchoolFri.DataBindings.Add("Text", bindingSource5, "SchoolName");
lbTeacherFri.DataBindings.Add("Text", bindingSource5, "FullName");
lbDurationFri.DataBindings.Add("Text", bindingSource5, "BookingDayDuration");
lbYear.DataBindings.Add("Text", bindingSource5, "Year");
cbSchoolFri.DataBindings.Add("Checked", bindingSource5, "SchoolContacted");
cbTeacherFri.DataBindings.Add("Checked", bindingSource5, "TeacherContacted");
cbEmailFri.DataBindings.Add("Checked", bindingSource5, "LetterSent");
dataRepeater5.DataSource = bindingSource5;
如果选中cbSchoolFriday,我想将Picture Box pbFriday的背景颜色更改为红色。我怎么能这样做?
截图 -
由于
答案 0 :(得分:1)
如果您想在不使用DataBindings
事件的情况下使用CheckedChanged
,可以使用以下解决方案:
Binding bind = new Binding("Checked", bindingSource5, "SchoolContacted");
bind.Format += (s,e) => {
e.Value = (int)e.Value == 1;
dataRepeater.ItemTemplate.BackColor = ((bool)e.Value) ? Color.Red : Color.White;
};
cbSchoolFri.DataBindings.Add(bind);
我不确定您的dataRepeater.ItemTemplate
是否有DataBindings
属性,以便我们可以使用dataRepeater.ItemTemplate.DataBindings
?
答案 1 :(得分:0)
我设法解决了这个问题。看来dataRepeater有一个DrawItem事件。在这里,我输入以下代码 -
private void dataRepeater1_DrawItem(object sender, Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
{
CheckBox cbSchoolMon = e.DataRepeaterItem.Controls["cbSchoolMon"] as CheckBox;
Label lbTeacherIDMon = e.DataRepeaterItem.Controls["lbTeacherIDMon"] as Label;
PictureBox pbMon = e.DataRepeaterItem.Controls["pbMon"] as PictureBox;
if (cbSchool.Checked)
{
pbMon.BackColor = Color.Red;
}
else
{
pbMon.BackColor = Color.Yellow;
}
}
感谢您的帮助。