且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何绑定列表<串GT;到DataGridView控件?

更新时间:2022-02-09 17:49:01

那是因为DataGridView中查找包含对象的属性。对于字符串只有一个属性 - 长度。所以,你需要的包装像这样的字符串

Thats because DataGridView looks for properties of containing objects. For string there is just one property - length. So, you need a wrapper for a string like this

public class StringValue
{
    public StringValue(string s)
    {
        _value = s;
    }
    public string Value { get { return _value; } set { _value = value; } }
    string _value;
}

然后绑定列表<&的StringValue GT; 对象网格。它的工作原理

Then bind List<StringValue> object to your grid. It works