开发者

Trying to load a list into a DataGridView Cell

I'm trying to display an object into a DataGridView using Reflection

so far everything works smootly but the problem is that some of the object's properties are Lists. How can I adapt my DataGridView to show a list?

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());

}


I found a pretty good tutorial that might help you: http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-collection

Update

I don't think you can automatically make a DataGridView cell display a list, but you might be able do it once your reflection detects it's list then you can manually do the following: http://msdn.microsoft.com/en-us/library/aa480727.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜