Simon,
You do not need an inherited control to bind to an object. You just need the
object, Windows Forms supplies the rest!
I don't see where reflection would help per se, it sounds like you want to
throw a lot of code at a problem that is simple enough to solve, with very
little code.
Of course if you want "better" design time support, a custom TextBox that
has a Person/Object property & a PropertyName property may be a good
alternative:
The "problem" with creating a custom TextBox, is you will need to create
custom versions of every other control. A Property Extender may be a better
alternative.
Here is a version of a custom TextBox:
Imports System.ComponentModel
Public Class BindableTextBox
Inherits TextBox
Private m_propertyName As String
Private m_dataSource As Object
Private m_dataMember As String
Public Sub New()
m_propertyName = String.Empty
m_dataSource = Nothing
m_dataMember = String.Empty
End Sub
<Category("Data"), DefaultValue("")> _
Public Property PropertyName() As String
Get
Return m_propertyName
End Get
Set(ByVal value As String)
m_propertyName = value
DataBind()
End Set
End Property
<Category("Data")> _
Public Property DataSource() As Object
Get
Return m_dataSource
End Get
Set(ByVal value As Object)
m_dataSource = value
DataBind()
End Set
End Property
<Category("Data"), DefaultValue("")> _
Public Property DataMember() As String
Get
Return m_dataMember
End Get
Set(ByVal value As String)
m_dataMember = value
DataBind()
End Set
End Property
Public Sub DataBind()
If m_propertyName Is Nothing Then Exit Sub
If m_dataSource Is Nothing Then Exit Sub
If m_dataMember Is Nothing Then Exit Sub
Me.DataBindings.Add(m_propertyName, m_dataSource, m_dataMember)
End Sub
End Class
On your form you can use BindableTextBox, use the designer to set the
DataMember & PropertyName properties, then within your code set the
DataSource property to an instance of your object.
For details on making the above class better behaved in the designer, check
out the following articles.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/usingpropgrid.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp
I would simply do all the Control.DataBindings.Add in the Set routine for
the object property on my form, then when I create the form I would set this
Object Property
Public Class PersonForm
Inherits System.Windows.Forms.Form
' designer generated code
Private m_person As Person
Public Property Person As Person
Get
Return m_person
End Get
Set(ByVal value As Person)
m_person = value
If value Is Nothing Then Exit Property
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Set
End Property
End Form
You should also include code in Person Set to un bind the previous person
object.
Hope this helps
Jay
Simon Verona said:
Could I perhaps then inherit the textbox and add fields for the "object
name" and property to map to and then get the object using reflection to do
the mapping in code from within the inherited control?? Or am I being too
ambitious????
Thanks for all your help so far.
Simon
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
<<snip>>