我有一个绑定到类的数据网格,其中有一些列被标记为[Browsable(false)]。这些列显示为空白。有没有什么办法可以把它关掉。
我没有使用任何自动绑定,而是自己创建列并设置DataPropertyName属性。
我花了很长时间才找到为什么它们是空白的,现在我希望有一些简单的方法来显示其中的值。我唯一能想到的就是编写我自己的DataGridViewColumn类并重新实现绑定。还有其他想法吗?
这里有一些代码演示了这个问题,GridBrowsableProblem是一个新的表单,上面放了一个DataGridView。当运行ProblemProperty没有值时。
public partial class GridBrowsableProblem : Form
{
public class ProblemTestClass
{
[Browsable(false)]
public string ProblemProperty { get; set; }
public string AnotherProperty { get; set; }
}
public GridBrowsableProblem()
{
InitializeComponent();
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
column1.DataPropertyName = "ProblemProperty";
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
column2.DataPropertyName = "AnotherProperty";
ProblemTestClass item = new ProblemTestClass();
item.ProblemProperty = "test1";
item.AnotherProperty = "test2";
BindingList<ProblemTestClass> bindingList = new BindingList<ProblemTestClass>();
bindingList.Add(item);
dataGridView1.Columns.Add(column1);
dataGridView1.Columns.Add(column2);
dataGridView1.DataSource = bindingList;
}
}发布于 2012-08-25 23:35:06
删除Browsable(false)属性或将其设置为true。
http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.browsableattributes(v=vs.90).aspx
https://stackoverflow.com/questions/9407973
复制相似问题