views:

116

answers:

2

I understand how Browsable attribute is supposed to work. It's supposed to hide a property from showing up in a PropertyGrid in design time.

It also has another effect in that it will stop a Property from showing up in components such as Grids, or specifically Infragistics WinGrid. I am not sure if it has this behaviour on regular Windows Forms grids.

This works, but it doesn't sound like Browsable is being use as intended when being used for 'Run time' displaying of a property on a grid component.

Any literature from Microsoft on proper use. Even though it works, I don't want to use this attribute to hide columns on a grid bound to a business object if it's not indeed the correct usage of the attribute, but rather something some grid vendors decided to use to determine property visibility on their grids.

A: 

The Microsoft "Browsable" attribute has nothing to do with hiding Grid columns.

It just specifies whether a property should be displayed in a Properties window of the Visual Studio Designer(or also PropertyGrid component). Members marked with the BrowsableAttribute to false are not appropriate for design-time editing and therefore are not displayed in a visual designer.

This is all about this attribute. We can't speack about "best practices" here, is like we discuss the best practices for the "Visible" button property.

serhio
Whan I think about Best Pracices, I am thinking from a stand point of developers who look for this attribute and apply their own version of behavior such as hiding the property at runtime in a grid.
Dan
I would suggest that Best Practices here could be answered how we answer something like best practices for a Visible property. A Visible property determines if a component is visible at runtime and therefore shouldn't have any other behaviour.You also say that "The Microsoft "Browsable" attribute has nothing to do with hiding Grid columns." Many component grids use this property for grids to show/hide certain columns at runtime. My question is relating to is this acceptable use of this property for a component developer
Dan
+1  A: 

There is no rule in the .NET Framework Guidelines that says that attributes should be exclusive to the kind of types for which it was designed or commonly used. Re-using them certainly helps the programmer having to memorize less class names, as long as s/he doesn't have to jump through hoops with using/Imports directives and assembly references. Not an issue with a Windows Forms control.

Giving an attribute runtime behavior when it normally gets used to affect design-time behavior wouldn't be my choice however. It's Infragistics, what can I say...

Hans Passant