我成功地将显示/值对添加到这样的组合框中:
List<Student> BRStudents =
studentsList.Where(h => h.EnrolledInAYttFM)
.Where(i =>
i.RecommendedNextTalkTypeID.Equals(BIBLE_READING_TALK_TYPE))
.OrderBy(j => j.WeekOfLastAssignment)
.ToList();
comboBoxBR.DataSource = BRStudents;
comboBoxBR.DisplayMember = "FullName";
comboBoxBR.ValueMember = "StudentID";
...但我随后(在某些情况下)想向 comboBoxBR 添加另一个项目,该项目不在 BRStudents 列表中。如果我尝试这样做:
AssignmentHistory ah = AYttFMConstsAndUtils.AssignmentHistList
.FirstOrDefault(i => i.WeekOfAssignment == currentWeek && i.TalkType == 1);
string fullName = AYttFMConstsAndUtils.GetStudentFullNameForID(ah.StudentID_FK);
comboBoxBR.Items.Add(fullName);
...我得到,“设置 DataSource 属性时无法修改项目集合。”
真的,我想做这样的事情:
comboBoxBR.Items.Add(fullName, ah.StudentID_FK);
有没有办法将两个结果(Student 列表和单个 AssignmentHistory)组合到 Dictionary 或一些这样的集合中,然后将其分配为 comboBoxBR 的 DataSource?
为了全面披露,以下是 Student 和 AssignmentHistory 的定义:
public class Student
{
public int StudentID { get; set; }
public int FamilyID { get; set; }
public bool EnrolledInAYttFM { get; set; }
public DateTime DateEnrolledOrHiatusAYttFM { get; set; }
public bool GivesBibleReading { get; set; }
public bool PresentsICRVBS { get; set; }
public bool IsHouseholder { get; set; }
public bool IsMale { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddr { get; set; }
public DateTime WeekOfLastAssignment { get; set; }
public int RecommendedNextTalkTypeID { get; set; }
public int NextCounselPoint { get; set; }
public string FullName => $"{FirstName} {LastName}";
}
public class AssignmentHistory
{
public DateTime WeekOfAssignment { get; set; }
public int TalkType { get; set; }
public int StudentID_FK { get; set; }
public int AssistantID_FK { get; set; }
public int CounselPoint { get; set; }
public bool HasBeenEmailed { get; set; }
public bool SlipHasBeenPrinted { get; set; }
}