Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Prevent binding to business object properties?
 

Prevent binding to business object properties?

Is there an attribute or something I can apply to properties in a business object to stop them being picked up by binding in a DataGridView? I've got a few system properties in the base class (IsDirty, IsNew etc) which obviously shouldn't be in the grids; I know I can remove the columns, but if there's a way to avoid it...
Mark_Rendle  Tuesday, June 12, 2007 9:23 PM
Set the properties Browsable attribute to false

Code Snippet

Imports System.ComponentModel

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As New List(Of MyData)
Dim m As New MyData
m.IsDirty = False
m.ProductName = "Ken"
lst.Add(m)
DataGridView1.DataSource = lst
End Sub
End Class


Public Class MyData
Private m_ProductName As String
Public Property ProductName() As String
Get
Return m_ProductName
End Get
Set(ByVal value As String)
m_ProductName = value
End Set
End Property

Private m_IsDirty As Boolean

<Browsable(False)> _
Public Property IsDirty() As Boolean
Get
Return m_IsDirty
End Get
Set(ByVal value As Boolean)
m_IsDirty = value
End Set
End Property

End Class


Ken Tucker  Wednesday, June 13, 2007 1:29 AM
Set the properties Browsable attribute to false

Code Snippet

Imports System.ComponentModel

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As New List(Of MyData)
Dim m As New MyData
m.IsDirty = False
m.ProductName = "Ken"
lst.Add(m)
DataGridView1.DataSource = lst
End Sub
End Class


Public Class MyData
Private m_ProductName As String
Public Property ProductName() As String
Get
Return m_ProductName
End Get
Set(ByVal value As String)
m_ProductName = value
End Set
End Property

Private m_IsDirty As Boolean

<Browsable(False)> _
Public Property IsDirty() As Boolean
Get
Return m_IsDirty
End Get
Set(ByVal value As Boolean)
m_IsDirty = value
End Set
End Property

End Class


Ken Tucker  Wednesday, June 13, 2007 1:29 AM
Thanks!
Mark_Rendle  Friday, June 22, 2007 9:03 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView: How to get rid of old DataTable.Colum
• Insert, Update, Delete
• how to view an event log in a datagrid.?
• Tab Control: Activate Data Binding on Tab Child controls without having to view the tab
• Can't use designer added column in TableAdapter update
• Xml
• binding source control
• DataGridView Color Picker
• Error by Creating a DataSet
• Using a datagrid for selecting records