最后我发现了一些东西。我不知道这是否是正确的方法,但它现在对我有用。这是我所做的:
1)我已经设置属性VirtualMode为true的datagridview。 2)我处理CellValueNeeded
事件。在此事件处理程序中,我检查列索引并设置值:
private void myDataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
if (e.ColumnIndex == 3)
{
// _appointments is a member variable which is the datasource of the grid
Appointment appointment = _appointments[e.RowIndex];
IList<DisciplineType> disciplines = appointment.GetDisciplines();
for (int i = 0; i < disciplines.Count; i++)
{
if (i > 0)
e.Value += ", " + disciplines[i].Description;
else
e.Value += disciplines[i].Description;
}
}
}
希望这可以帮助其他人。或者,如果您有更好的解决方案,请告诉我。