English 中文(简体)
使一个属性在 DataGridView 中可见, 但不是在属性Grid吗?
原标题:Make a property visible in DataGridView but NOT in PropertyGrid?

假设我有一个在 DataGridView 中显示的属性, 但不是在属性Grid 中显示同一对象时显示的属性。 我知道可以使用 < code> [browsable(false)] , 但可以在两个视图中隐藏它。 我也可以使用 < code> gridView. columns[“blah”]. 。 可视= feal; , 但它与我想要的相反, 因为它隐藏在 DataGridView 中, 但不是在属性Grid。 是否有办法可以反向? (创建全新数据表只是为了将同一数据保持一个字段减去一个字段, 并且将所有数据都重新绑在一起, 而不是要真正用 klugt 的方式来做事情 。) 或者, 我可以使用一个在实际类上不存在的数据GridV 上添加一列的解决方案 。

最佳回答

it is possible to solve this issue by using the BrowsableAttributes property of a PropertyGrid. First, create a new attribute like this:

public class PropertyGridBrowsableAttribute : Attribute
{
    private bool browsable;
    public PropertyGridBrowsableAttribute(bool browsable){
        this.browsable = browsable;
    }
}

然后将此属性添加到您想要显示在属性“属性”中的所有属性中 :

[DisplayName("First Name"), Category("Names"), PropertyGridBrowsable(true)]
public string FirstName {
    get { return ... }
    set { ... }
}

然后设置这样的浏览可扩展属性 :

myPropertyGrid.BrowsableAttributes = new AttributeCollection(
    new Attribute[] { new PropertyGridBrowsableAttribute(true) });

这将只显示您财产网格中的属性, 而 DataGridView 仍然可以访问所有属性, 只需稍加努力编码 。

我仍然会和Tergiver一起去,把这种行为称为 " 错误 ",因为浏览属性的文件清楚说明它只用于财产窗口。

(credit to user "maro" at

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...