DataGridView默认情况下会显示所绑定对象的属性,如绑定一个List<User>,User的Name、Age、Gender等属性会作为Column的内容显示出来。对于一个字符串来说,只有一个实例属性Length,因此显示的即为字符串的长度了。当然,如果有其他属性存在,仍然会作为Column显示出来。
要想使DataGridView显示字符串集合,可以使用匿名类型将字符串进行包装:
var test = new List<string> { "just", "a", "test" };
dataGridView1.DataSource = (from s in test select new { s }).ToList();