首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将datagridview绑定到[Browsable(false)]列

将datagridview绑定到[Browsable(false)]列
EN

Stack Overflow用户
提问于 2012-02-23 14:02:27
回答 1查看 605关注 0票数 1

我有一个绑定到类的数据网格,其中有一些列被标记为[Browsable(false)]。这些列显示为空白。有没有什么办法可以把它关掉。

我没有使用任何自动绑定,而是自己创建列并设置DataPropertyName属性。

我花了很长时间才找到为什么它们是空白的,现在我希望有一些简单的方法来显示其中的值。我唯一能想到的就是编写我自己的DataGridViewColumn类并重新实现绑定。还有其他想法吗?

这里有一些代码演示了这个问题,GridBrowsableProblem是一个新的表单,上面放了一个DataGridView。当运行ProblemProperty没有值时。

代码语言:javascript
复制
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;
    }
}
EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9407973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档