我只是想知道是否可以将属性应用于业务对象(MyBusinessObject)中的属性,以便在网格的DataSource设置为List(Of MyBusinessObject)之后,列的visible属性将自动是假的。例如:
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
我希望这是有道理的。谢谢!
编辑:我想澄清一下 - 我仍然希望MyProperty4成为数据绑定,我只是不希望列可见。答案 0 :(得分:2)
在您的课程中使用BrowsableAttribute(<Browsable(False)>
)属性应该可以满足您的需求,但我相信这是对该属性的“标签外”使用。
如果这不符合您的需要,那么您需要创建自己的属性并对绑定类型使用反射来确定应隐藏哪些列然后隐藏它们。
<强>更新强>
您可能还需要考虑第三方网格控件,例如Infragistics或Telerik(我们使用的只有两个,没有其他原因可供选择)。这使得执行这样的任务变得更加容易。