0

我正在使用以下内容在转发器中替换一些数据 -

        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 的背景颜色更改为红色。我怎样才能做到这一点?

截屏 - 在此处输入图像描述

谢谢

4

2 回答 2

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

于 2013-06-18T08:28:10.850 回答
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;
        }
    }

谢谢你的帮助。

于 2013-06-18T10:09:47.517 回答