<i id='y0bp9'><tr id='y0bp9'><dt id='y0bp9'><q id='y0bp9'><span id='y0bp9'><b id='y0bp9'><form id='y0bp9'><ins id='y0bp9'></ins><ul id='y0bp9'></ul><sub id='y0bp9'></sub></form><legend id='y0bp9'></legend><bdo id='y0bp9'><pre id='y0bp9'><center id='y0bp9'></center></pre></bdo></b><th id='y0bp9'></th></span></q></dt></tr></i><div id='y0bp9'><tfoot id='y0bp9'></tfoot><dl id='y0bp9'><fieldset id='y0bp9'></fieldset></dl></div>

      <small id='y0bp9'></small><noframes id='y0bp9'>

      • <bdo id='y0bp9'></bdo><ul id='y0bp9'></ul>

      <tfoot id='y0bp9'></tfoot>
    1. <legend id='y0bp9'><style id='y0bp9'><dir id='y0bp9'><q id='y0bp9'></q></dir></style></legend>

        是否有一个属性我可以在我的类中使用来告诉 DataGridView 在绑定到列表时不要为其创建列&lt;MyCl

        时间:2023-07-27
        <legend id='3wO3E'><style id='3wO3E'><dir id='3wO3E'><q id='3wO3E'></q></dir></style></legend>
          1. <small id='3wO3E'></small><noframes id='3wO3E'>

            <i id='3wO3E'><tr id='3wO3E'><dt id='3wO3E'><q id='3wO3E'><span id='3wO3E'><b id='3wO3E'><form id='3wO3E'><ins id='3wO3E'></ins><ul id='3wO3E'></ul><sub id='3wO3E'></sub></form><legend id='3wO3E'></legend><bdo id='3wO3E'><pre id='3wO3E'><center id='3wO3E'></center></pre></bdo></b><th id='3wO3E'></th></span></q></dt></tr></i><div id='3wO3E'><tfoot id='3wO3E'></tfoot><dl id='3wO3E'><fieldset id='3wO3E'></fieldset></dl></div>
            • <bdo id='3wO3E'></bdo><ul id='3wO3E'></ul>
                  <tbody id='3wO3E'></tbody>
              1. <tfoot id='3wO3E'></tfoot>

                • 本文介绍了是否有一个属性我可以在我的类中使用来告诉 DataGridView 在绑定到列表时不要为其创建列&lt;MyClass&gt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这样的课:

                  private class MyClass {
                    [DisplayName("Foo/Bar")]
                    public string FooBar { get; private set; }
                    public string Baz { get; private set; }      
                    public bool Enabled;
                  }
                  

                  当我创建 List 并将其分配给 DataGridViewDataSource 时,网格会显示两列,"Foo/Bar"和Baz".这就是我想要发生的事情.

                  When I create a List<MyClass> and assign it to the DataSource of a DataGridView, the grid shows me two columns, "Foo/Bar" and "Baz". This is what I want to happen.

                  它目前有效,因为 Enabled 是一个字段,而不是一个属性 - DataGridView 只会获取属性.然而,这是一个肮脏的黑客.

                  It currently works because Enabled is a field, not a property - DataGridView will only pick up properties. However, this is a dirty hack.

                  我也想将 Enabled 设为属性,但仍将其隐藏在 DataGridView 上.

                  I would like to make Enabled a property too, but still hide it on the DataGridView.

                  我知道我可以在绑定后手动删除该列..但这并不理想.

                  I know I can manually delete the column after binding.. but that's not ideal.

                  是否有类似于 DisplayName 的属性,我可以用它来标记属性?[Visible(false)] 之类的东西?

                  Is there an attribute similar to DisplayName, that I can tag a property with? Something like [Visible(false)] ?

                  推荐答案

                  [Browsable(false)] 将隐藏 DataGridView 的属性.

                  视觉设计器通常会在属性"窗口中显示那些没有可浏览属性或标有BrowsableAttribute 构造函数的可浏览参数设置为 true.这些成员可以在设计时进行修改.标有BrowsableAttribute 构造函数的可浏览参数设置为 false 是不适合设计时编辑,因此不适合显示在视觉设计器中.默认为真.

                  A visual designer typically displays in the Properties window those members that either have no browsable attribute or are marked with the BrowsableAttribute constructor's browsable parameter set to true. These members can be modified at design time. Members marked with the BrowsableAttribute constructor's browsable parameter set to false are not appropriate for design-time editing and therefore are not displayed in a visual designer. The default is true.

                  这篇关于是否有一个属性我可以在我的类中使用来告诉 DataGridView 在绑定到列表时不要为其创建列&lt;MyClass&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C# 是否有“ThreadLocal"?模拟(对于数据成员)到“ThreadStatic";属性? 下一篇:C# 方法属性不能包含 Lambda 表达式?

                  相关文章

                  <small id='l2PWL'></small><noframes id='l2PWL'>

                  1. <i id='l2PWL'><tr id='l2PWL'><dt id='l2PWL'><q id='l2PWL'><span id='l2PWL'><b id='l2PWL'><form id='l2PWL'><ins id='l2PWL'></ins><ul id='l2PWL'></ul><sub id='l2PWL'></sub></form><legend id='l2PWL'></legend><bdo id='l2PWL'><pre id='l2PWL'><center id='l2PWL'></center></pre></bdo></b><th id='l2PWL'></th></span></q></dt></tr></i><div id='l2PWL'><tfoot id='l2PWL'></tfoot><dl id='l2PWL'><fieldset id='l2PWL'></fieldset></dl></div>

                      <tfoot id='l2PWL'></tfoot>
                    1. <legend id='l2PWL'><style id='l2PWL'><dir id='l2PWL'><q id='l2PWL'></q></dir></style></legend>
                        <bdo id='l2PWL'></bdo><ul id='l2PWL'></ul>