我正在尝试使用反射将对象显示到DataGridView中
到目前为止,一切工作都很顺利,但问题是对象的一些属性是列表。如何调整DataGridView以显示列表?
public void SetDataSource(PluginBase plugin)
{
dgvProperties.Rows.Clear();
List<DataGridViewRow> rows = new List<DataGridViewRow>();
foreach (PropertyInfo info in typeof(PluginBase).GetProperties(BindingFlags.Public|BindingFlags.Instance))
{
object value = plugin.GetType().GetProperty(info.Name).GetValue(plugin, null);
object[] o = new object[2];
o[0] = info.Name;
o[1] = value;
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.CreateCells(dgvProperties, o);
rows.Add(dgvr);
}
dgvProperties.Rows.AddRange(rows.ToArray());
}