I was just wondering if it is possible to apply an attribute to a property within a business object (MyBusinessObject) such that after the DataSource of a grid is set to a List(Of MyBusinessObject), the visible property of the column will automatically be false. For example:
myGrid.DataSource = New List(Of MyBusinessObject)
Public Class MyBusinessObject
'I want these three columns to be visible after data binding
<DisplayName("Property 1")> _
Public Property MyProperty1 As String
<DisplayName("Property 2")> _
Public Property MyProperty2 As Integer
<DisplayName("Property 3")> _
Public Property MyProperty3 As String
'I want this column to have Visible = False after data binding
Public Property MyProperty4 As Integer
End Class
I hope this makes sense. Thanks!
EDIT: I would like to clarify – I would still like MyProperty4 to be databound, I just do not want the column to be visible.
Using the BrowsableAttribute (
<Browsable(False)>) attribute in your class should accomplish what you need, however I believe that this is an “off-label” use of the attribute.If this does not meet your needs, then you will need to create your own attribute and use reflection on your bound type to determine which columns should be hidden and then hide them.
Update
You may also want to consider third-party grid controls, such as Infragistics or Telerik (just two that we use, no other reason for their selection). These make it much easier to perform tasks like this.