Hiding members for the DataSource window

Posted Mon, Oct 17 2005 12:17 by bill

The new DataSource window in VS.NET 2005 truely rocks !  I love how you can have all different kinds of data sources in there, be it your web services, data from your database or *ANY* type in your project including, of course, your business objects. 

So when you do add business objects to the DataSource window, you may find it shows properties you don't want people to bind to, yet you still want them to be able to access those peoperties in code.  The solution is very simple. Simply mark the properties with the:

<System.ComponentModel.Browsable(False)> _

attribute, and they won't show up in the Datasource window and the binding source will throw an error if they are attempted to be bound against. 

What I found really nice was I had an abstract base class (MustInhertit) with some abstract properties defined in it (MustOverride) and applying the attribute there in the base class cascaded through nicely to all derived classes.  Of course the derived classes with their Overrides in them could re-appy the attribute setting it to either True or False, to show or hide the property respectively .  sweet smile

Filed under: ,


# re: Hiding members for the DataSource window

Monday, October 17, 2005 2:51 PM by bill

Of course, one thing to remember (I'm sure I'm not talking to Bill here but anyone else who reads this post smile is that the Browsable attribute is used in more places than just the the DataSource window.

A common control we use here at my work is the propertygrid (one of my favourite controls) and to have public properties not come up in the grid for any given object you also use the browsable attribute.

By hiding in one you hide from the others.

However: one of the extremely cool things coming in VS2005 (of the many extremely cool things) is that attributes propogate. Very very cool. I remember Joe Cooney mentioning at codecamp that is you define an interface with a method marked as a <webmethod> then a class that implements it will also have the webmethod attribute exposed. Sah-weet!

# Re: Hiding members for the DataSource window

Monday, October 17, 2005 3:07 PM by bill

Hey Geoff,

Yeh I was expecting it to be System.ComponentModel.Bindable. Logically that makes more sense to me, although I can see advantages in using an already exisitng attribute. Ideally I think it should support both, so you can choose what level of hiding you want.