473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Data Binding to a object...

I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in this
case the object represents a customer). Can I then use this object to
databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for example
updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon
Nov 20 '05 #1
19 2304
As long as your object implements IList, ICollection, IEnumerable then you
should be OK

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in this
case the object represents a customer). Can I then use this object to
databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon

Nov 20 '05 #2
OHM

I don't suppose you've got any references to actual code examples /
walkthroughs? I'm searching through google, but as usual... it's not the
answer that matters, it's the correct question - which is obviously alluding
me!

Many thanks for your help.

Simon
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:eU*************@TK2MSFTNGP11.phx.gbl...
As long as your object implements IList, ICollection, IEnumerable then you
should be OK

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for

example
updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon


Nov 20 '05 #3
Hi,

Don’t forget Implements IEditableObject if you want to be able to
change the bound data.

Ken
---------------------

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message news:eU*************@TK2MSFTNGP11.phx.gbl:
As long as your object implements IList, ICollection, IEnumerable then you

should be OK


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004
Nov 20 '05 #4
Hi,

http://www.onteorasoftware.com/downl...todatagrid.zip

Ken
----------------

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl:
OHM

I don't suppose you've got any references to actual code examples /
walkthroughs? I'm searching through google, but as usual... it's not the

answer that matters, it's the correct question - which is obviously
alluding
me!

Many thanks for your help.

Simon
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message
news:eU*************@TK2MSFTNGP11.phx.gbl...
As long as your object implements IList, ICollection, IEnumerable then
you
should be OK

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Simon Verona" <HYPERLINK
"mailto:ne**@aphroditeuk.com"ne**@aphroditeuk. com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...

I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in
this
case the object represents a customer). Can I then use this
object
to
databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for
example

updating one property may actually update several database fields
for
example.

Hope I've explained this clear enough...

Regards
Simon



--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004
Nov 20 '05 #5
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable if
you want to "edit" a list of items. If you have a single item, you do not
need to implement those interfaces.

In my experience IEditableObject is useful but not required to change bound
data, if you fully implement IEditableObject you can cancel the change,
without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in this
case the object represents a customer). Can I then use this object to
databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon

Nov 20 '05 #6
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable if
you want to "edit" a list of items. If you have a single item, you do not
need to implement those interfaces.

In my experience IEditableObject is useful but not required to change bound data, if you fully implement IEditableObject you can cancel the change,
without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for

example
updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon


Nov 20 '05 #7
Terry,
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1 That's because I left out the notification. :-( Here is a version with
Notifications. :-)

Public Class Person

Public Event Text1Changed As EventHandler
Public Event Text2Changed As EventHandler

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
OnText1Changed(EventArgs.Empty)
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
OnText2Changed(EventArgs.Empty)
End Set
End Property

Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
RaiseEvent Text1Changed(Me, e)
End Sub

Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
RaiseEvent Text2Changed(Me, e)
End Sub

End Class

I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
changes it in TextBox1!

I don't have a clear link that explains the above, if you want it or need it
I can look for it later.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable if
you want to "edit" a list of items. If you have a single item, you do not need to implement those interfaces.

In my experience IEditableObject is useful but not required to change

bound
data, if you fully implement IEditableObject you can cancel the change,
without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in

this case the object represents a customer). Can I then use this object to databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for

example
updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon



Nov 20 '05 #8
So do I read it that I don't need to implement all the interfaces if I just
have a single record ????

Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
Terry,
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1 That's because I left out the notification. :-( Here is a version with
Notifications. :-)

Public Class Person

Public Event Text1Changed As EventHandler
Public Event Text2Changed As EventHandler

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
OnText1Changed(EventArgs.Empty)
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
OnText2Changed(EventArgs.Empty)
End Set
End Property

Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
RaiseEvent Text1Changed(Me, e)
End Sub

Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
RaiseEvent Text2Changed(Me, e)
End Sub

End Class

I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
changes it in TextBox1!

I don't have a clear link that explains the above, if you want it or need

it I can look for it later.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable
if you want to "edit" a list of items. If you have a single item, you do not need to implement those interfaces.

In my experience IEditableObject is useful but not required to change

bound
data, if you fully implement IEditableObject you can cancel the
change, without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
> I'm not sure if I'm going down the correct route...
>
> I have a class which exposes a number of properties of an object (in

this
> case the object represents a customer). Can I then use this object to
> databind to text boxes etc?
>
> I can't use a dataset as the object has loads of derived logic, for
example
> updating one property may actually update several database fields

for > example.
>
> Hope I've explained this clear enough...
>
> Regards
> Simon
>
>



Nov 20 '05 #9
Simon,
As I stated earlier: Correct! you don't need to implement any interfaces if
you have a single object ("record").

You need to include a Text1Changed event for the Text1 property, if you can
change the object outside of the form, if only the form can change the
object/property, then the event is not as important.

The "Changed" event needs to be named the same as the property, with Changed
as the suffix, as my Person example shows.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
So do I read it that I don't need to implement all the interfaces if I just have a single record ????

Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
Terry,
The only problem with this is that if you change the aPerson.Text1 value this is not reflected in the TextBox1 That's because I left out the notification. :-( Here is a version with
Notifications. :-)

Public Class Person

Public Event Text1Changed As EventHandler
Public Event Text2Changed As EventHandler

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
OnText1Changed(EventArgs.Empty)
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
OnText2Changed(EventArgs.Empty)
End Set
End Property

Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
RaiseEvent Text1Changed(Me, e)
End Sub

Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
RaiseEvent Text2Changed(Me, e)
End Sub

End Class

I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
changes it in TextBox1!

I don't have a clear link that explains the above, if you want it or need it
I can look for it later.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in

message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The only problem with this is that if you change the aPerson.Text1 value this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:OC**************@TK2MSFTNGP12.phx.gbl...
> Simon,
> As OHM suggested, you need to implement IList, ICollection, IEnumerable
if
> you want to "edit" a list of items. If you have a single item, you do not
> need to implement those interfaces.
>
> In my experience IEditableObject is useful but not required to

change bound
> data, if you fully implement IEditableObject you can cancel the

change, > without IEditableObject the change is made, period.
>
> This article appears to be a good starting point on data binding.
> http://support.microsoft.com/default...b;en-us;313482
>
>
> Here is a simple sample of binding to an Object:
>
> Public Class Person
>
> Private m_text1 As String
> Private m_text2 As String
>
> Public Sub New()
> m_text1 = String.Empty
> m_text2 = String.Empty
> End Sub
>
> Public Property Text1() As String
> Get
> Return m_text1
> End Get
> Set(ByVal value As String)
> m_text1 = value
> End Set
> End Property
>
> Public Property Text2() As String
> Get
> Return m_text2
> End Get
> Set(ByVal value As String)
> m_text2 = value
> End Set
> End Property
>
> End Class
>
>
> Public Class PersonForm
> Inherits System.Windows.Forms.Form
>
> ' ... designer generated code
>
> Private aPerson As New Person
>
> Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
> Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
> End Sub
>
> End Class
>
> Hope this helps
> Jay
>
>
>
> "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> news:e3**************@TK2MSFTNGP09.phx.gbl...
> > I'm not sure if I'm going down the correct route...
> >
> > I have a class which exposes a number of properties of an object (in this
> > case the object represents a customer). Can I then use this object to
> > databind to text boxes etc?
> >
> > I can't use a dataset as the object has loads of derived logic, for > example
> > updating one property may actually update several database fields for > > example.
> >
> > Hope I've explained this clear enough...
> >
> > Regards
> > Simon
> >
> >
>
>



Nov 20 '05 #10
Terry,
I found an article that explains binding to an object.

http://msdn.microsoft.com/library/de...et02252003.asp

The Design Guidelines for Class Library Developers also discusses the
events...

http://msdn.microsoft.com/library/de...Guidelines.asp

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable if
you want to "edit" a list of items. If you have a single item, you do not need to implement those interfaces.

In my experience IEditableObject is useful but not required to change

bound
data, if you fully implement IEditableObject you can cancel the change,
without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
I'm not sure if I'm going down the correct route...

I have a class which exposes a number of properties of an object (in

this case the object represents a customer). Can I then use this object to databind to text boxes etc?

I can't use a dataset as the object has loads of derived logic, for

example
updating one property may actually update several database fields for
example.

Hope I've explained this clear enough...

Regards
Simon



Nov 20 '05 #11
Thanks, I'll take a read and see what I can learn here !

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
Terry,
I found an article that explains binding to an object.

http://msdn.microsoft.com/library/de...et02252003.asp
The Design Guidelines for Class Library Developers also discusses the
events...

http://msdn.microsoft.com/library/de...Guidelines.asp
Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
The only problem with this is that if you change the aPerson.Text1 value
this is not reflected in the TextBox1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OC**************@TK2MSFTNGP12.phx.gbl...
Simon,
As OHM suggested, you need to implement IList, ICollection, IEnumerable
if you want to "edit" a list of items. If you have a single item, you do not need to implement those interfaces.

In my experience IEditableObject is useful but not required to change

bound
data, if you fully implement IEditableObject you can cancel the
change, without IEditableObject the change is made, period.

This article appears to be a good starting point on data binding.
http://support.microsoft.com/default...b;en-us;313482
Here is a simple sample of binding to an Object:

Public Class Person

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
End Set
End Property

End Class
Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
End Sub

End Class

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
> I'm not sure if I'm going down the correct route...
>
> I have a class which exposes a number of properties of an object (in

this
> case the object represents a customer). Can I then use this object to
> databind to text boxes etc?
>
> I can't use a dataset as the object has loads of derived logic, for
example
> updating one property may actually update several database fields

for > example.
>
> Hope I've explained this clear enough...
>
> Regards
> Simon
>
>



Nov 20 '05 #12
Thanks Jay...

I've got it working using the data binding in code...

I'd like to be able to do the data-binding in the designer.... I guess I
need another interface?

Regards
Simon

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
Simon,
As I stated earlier: Correct! you don't need to implement any interfaces if you have a single object ("record").

You need to include a Text1Changed event for the Text1 property, if you can change the object outside of the form, if only the form can change the
object/property, then the event is not as important.

The "Changed" event needs to be named the same as the property, with Changed as the suffix, as my Person example shows.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
So do I read it that I don't need to implement all the interfaces if I

just
have a single record ????

Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
Terry,
> The only problem with this is that if you change the aPerson.Text1 value > this is not reflected in the TextBox1
That's because I left out the notification. :-( Here is a version with
Notifications. :-)

Public Class Person

Public Event Text1Changed As EventHandler
Public Event Text2Changed As EventHandler

Private m_text1 As String
Private m_text2 As String

Public Sub New()
m_text1 = String.Empty
m_text2 = String.Empty
End Sub

Public Property Text1() As String
Get
Return m_text1
End Get
Set(ByVal value As String)
m_text1 = value
OnText1Changed(EventArgs.Empty)
End Set
End Property

Public Property Text2() As String
Get
Return m_text2
End Get
Set(ByVal value As String)
m_text2 = value
OnText2Changed(EventArgs.Empty)
End Set
End Property

Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
RaiseEvent Text1Changed(Me, e)
End Sub

Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
RaiseEvent Text2Changed(Me, e)
End Sub

End Class

I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
changes it in TextBox1!

I don't have a clear link that explains the above, if you want it or need
it
I can look for it later.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in

message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> The only problem with this is that if you change the aPerson.Text1

value > this is not reflected in the TextBox1
>
> --
>
> OHM ( Terry Burns )
> . . . One-Handed-Man . . .
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:OC**************@TK2MSFTNGP12.phx.gbl...
> > Simon,
> > As OHM suggested, you need to implement IList, ICollection,

IEnumerable
if
> > you want to "edit" a list of items. If you have a single item, you do not
> > need to implement those interfaces.
> >
> > In my experience IEditableObject is useful but not required to change > bound
> > data, if you fully implement IEditableObject you can cancel the

change,
> > without IEditableObject the change is made, period.
> >
> > This article appears to be a good starting point on data binding.
> > http://support.microsoft.com/default...b;en-us;313482
> >
> >
> > Here is a simple sample of binding to an Object:
> >
> > Public Class Person
> >
> > Private m_text1 As String
> > Private m_text2 As String
> >
> > Public Sub New()
> > m_text1 = String.Empty
> > m_text2 = String.Empty
> > End Sub
> >
> > Public Property Text1() As String
> > Get
> > Return m_text1
> > End Get
> > Set(ByVal value As String)
> > m_text1 = value
> > End Set
> > End Property
> >
> > Public Property Text2() As String
> > Get
> > Return m_text2
> > End Get
> > Set(ByVal value As String)
> > m_text2 = value
> > End Set
> > End Property
> >
> > End Class
> >
> >
> > Public Class PersonForm
> > Inherits System.Windows.Forms.Form
> >
> > ' ... designer generated code
> >
> > Private aPerson As New Person
> >
> > Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As > > System.EventArgs) Handles MyBase.Load
> > Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
> > Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
> > End Sub
> >
> > End Class
> >
> > Hope this helps
> > Jay
> >
> >
> >
> > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > I'm not sure if I'm going down the correct route...
> > >
> > > I have a class which exposes a number of properties of an object (in > this
> > > case the object represents a customer). Can I then use this

object
> to
> > > databind to text boxes etc?
> > >
> > > I can't use a dataset as the object has loads of derived logic, for > > example
> > > updating one property may actually update several database

fields for
> > > example.
> > >
> > > Hope I've explained this clear enough...
> > >
> > > Regards
> > > Simon
> > >
> > >
> >
> >
>
>



Nov 20 '05 #13
Simon,
As far as I can tell the designer data-binding requires binding to a list of
items.

I am not aware of any interface that will enable you to bind in the designer
to a single object. Other then Making your single object appear to be a
list, which IMHO is more work then simply adding the data binding
manually...

Considering there is more work on defining the object to support data
binding, then the databinding itself, I personally don't have a problem with
this.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
Thanks Jay...

I've got it working using the data binding in code...

I'd like to be able to do the data-binding in the designer.... I guess I need another interface?

Regards
Simon

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
Simon,
As I stated earlier: Correct! you don't need to implement any interfaces if
you have a single object ("record").

You need to include a Text1Changed event for the Text1 property, if you

can
change the object outside of the form, if only the form can change the
object/property, then the event is not as important.

The "Changed" event needs to be named the same as the property, with

Changed
as the suffix, as my Person example shows.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
So do I read it that I don't need to implement all the interfaces if I

just
have a single record ????

Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:ex**************@TK2MSFTNGP09.phx.gbl...
> Terry,
> > The only problem with this is that if you change the aPerson.Text1

value
> > this is not reflected in the TextBox1
> That's because I left out the notification. :-( Here is a version with > Notifications. :-)
>
> Public Class Person
>
> Public Event Text1Changed As EventHandler
> Public Event Text2Changed As EventHandler
>
> Private m_text1 As String
> Private m_text2 As String
>
> Public Sub New()
> m_text1 = String.Empty
> m_text2 = String.Empty
> End Sub
>
> Public Property Text1() As String
> Get
> Return m_text1
> End Get
> Set(ByVal value As String)
> m_text1 = value
> OnText1Changed(EventArgs.Empty)
> End Set
> End Property
>
> Public Property Text2() As String
> Get
> Return m_text2
> End Get
> Set(ByVal value As String)
> m_text2 = value
> OnText2Changed(EventArgs.Empty)
> End Set
> End Property
>
> Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
> RaiseEvent Text1Changed(Me, e)
> End Sub
>
> Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
> RaiseEvent Text2Changed(Me, e)
> End Sub
>
> End Class
>
> I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above > changes it in TextBox1!
>
> I don't have a clear link that explains the above, if you want it or

need
it
> I can look for it later.
>
> Hope this helps
> Jay
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message
> news:%2****************@TK2MSFTNGP11.phx.gbl...
> > The only problem with this is that if you change the aPerson.Text1

value
> > this is not reflected in the TextBox1
> >
> > --
> >
> > OHM ( Terry Burns )
> > . . . One-Handed-Man . . .
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
> > news:OC**************@TK2MSFTNGP12.phx.gbl...
> > > Simon,
> > > As OHM suggested, you need to implement IList, ICollection,
IEnumerable
> if
> > > you want to "edit" a list of items. If you have a single item, you
do
> not
> > > need to implement those interfaces.
> > >
> > > In my experience IEditableObject is useful but not required to

change
> > bound
> > > data, if you fully implement IEditableObject you can cancel the
change,
> > > without IEditableObject the change is made, period.
> > >
> > > This article appears to be a good starting point on data
binding. > > > http://support.microsoft.com/default...b;en-us;313482
> > >
> > >
> > > Here is a simple sample of binding to an Object:
> > >
> > > Public Class Person
> > >
> > > Private m_text1 As String
> > > Private m_text2 As String
> > >
> > > Public Sub New()
> > > m_text1 = String.Empty
> > > m_text2 = String.Empty
> > > End Sub
> > >
> > > Public Property Text1() As String
> > > Get
> > > Return m_text1
> > > End Get
> > > Set(ByVal value As String)
> > > m_text1 = value
> > > End Set
> > > End Property
> > >
> > > Public Property Text2() As String
> > > Get
> > > Return m_text2
> > > End Get
> > > Set(ByVal value As String)
> > > m_text2 = value
> > > End Set
> > > End Property
> > >
> > > End Class
> > >
> > >
> > > Public Class PersonForm
> > > Inherits System.Windows.Forms.Form
> > >
> > > ' ... designer generated code
> > >
> > > Private aPerson As New Person
> > >
> > > Private Sub SamSpadeForm_Load(ByVal sender As Object, ByVal e As > > > System.EventArgs) Handles MyBase.Load
> > > Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
> > > Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
> > > End Sub
> > >
> > > End Class
> > >
> > > Hope this helps
> > > Jay
> > >
> > >
> > >
> > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > > I'm not sure if I'm going down the correct route...
> > > >
> > > > I have a class which exposes a number of properties of an
object
(in
> > this
> > > > case the object represents a customer). Can I then use
this object
> > to
> > > > databind to text boxes etc?
> > > >
> > > > I can't use a dataset as the object has loads of derived

logic, for
> > > example
> > > > updating one property may actually update several database

fields for
> > > > example.
> > > >
> > > > Hope I've explained this clear enough...
> > > >
> > > > Regards
> > > > Simon
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #14
If the OP is building an inherited control then custom properties can be
bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
Simon,
As far as I can tell the designer data-binding requires binding to a list of items.

I am not aware of any interface that will enable you to bind in the designer to a single object. Other then Making your single object appear to be a
list, which IMHO is more work then simply adding the data binding
manually...

Considering there is more work on defining the object to support data
binding, then the databinding itself, I personally don't have a problem with this.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
Thanks Jay...

I've got it working using the data binding in code...

I'd like to be able to do the data-binding in the designer.... I guess
I
need another interface?

Regards
Simon

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:Of**************@TK2MSFTNGP12.phx.gbl...
Simon,
As I stated earlier: Correct! you don't need to implement any interfaces
if
you have a single object ("record").

You need to include a Text1Changed event for the Text1 property, if
you can
change the object outside of the form, if only the form can change the
object/property, then the event is not as important.

The "Changed" event needs to be named the same as the property, with Changed
as the suffix, as my Person example shows.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> So do I read it that I don't need to implement all the interfaces if

I just
> have a single record ????
>
> Simon
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:ex**************@TK2MSFTNGP09.phx.gbl...
> > Terry,
> > > The only problem with this is that if you change the aPerson.Text1 value
> > > this is not reflected in the TextBox1
> > That's because I left out the notification. :-( Here is a version

with > > Notifications. :-)
> >
> > Public Class Person
> >
> > Public Event Text1Changed As EventHandler
> > Public Event Text2Changed As EventHandler
> >
> > Private m_text1 As String
> > Private m_text2 As String
> >
> > Public Sub New()
> > m_text1 = String.Empty
> > m_text2 = String.Empty
> > End Sub
> >
> > Public Property Text1() As String
> > Get
> > Return m_text1
> > End Get
> > Set(ByVal value As String)
> > m_text1 = value
> > OnText1Changed(EventArgs.Empty)
> > End Set
> > End Property
> >
> > Public Property Text2() As String
> > Get
> > Return m_text2
> > End Get
> > Set(ByVal value As String)
> > m_text2 = value
> > OnText2Changed(EventArgs.Empty)
> > End Set
> > End Property
> >
> > Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
> > RaiseEvent Text1Changed(Me, e)
> > End Sub
> >
> > Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
> > RaiseEvent Text2Changed(Me, e)
> > End Sub
> >
> > End Class
> >
> > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above > > changes it in TextBox1!
> >
> > I don't have a clear link that explains the above, if you want it or need
> it
> > I can look for it later.
> >
> > Hope this helps
> > Jay
> >
> > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in > message
> > news:%2****************@TK2MSFTNGP11.phx.gbl...
> > > The only problem with this is that if you change the aPerson.Text1 value
> > > this is not reflected in the TextBox1
> > >
> > > --
> > >
> > > OHM ( Terry Burns )
> > > . . . One-Handed-Man . . .
> > >
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in > message
> > > news:OC**************@TK2MSFTNGP12.phx.gbl...
> > > > Simon,
> > > > As OHM suggested, you need to implement IList, ICollection,
> IEnumerable
> > if
> > > > you want to "edit" a list of items. If you have a single item, you do
> > not
> > > > need to implement those interfaces.
> > > >
> > > > In my experience IEditableObject is useful but not required to
change
> > > bound
> > > > data, if you fully implement IEditableObject you can cancel the > change,
> > > > without IEditableObject the change is made, period.
> > > >
> > > > This article appears to be a good starting point on data binding. > > > > http://support.microsoft.com/default...b;en-us;313482
> > > >
> > > >
> > > > Here is a simple sample of binding to an Object:
> > > >
> > > > Public Class Person
> > > >
> > > > Private m_text1 As String
> > > > Private m_text2 As String
> > > >
> > > > Public Sub New()
> > > > m_text1 = String.Empty
> > > > m_text2 = String.Empty
> > > > End Sub
> > > >
> > > > Public Property Text1() As String
> > > > Get
> > > > Return m_text1
> > > > End Get
> > > > Set(ByVal value As String)
> > > > m_text1 = value
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property Text2() As String
> > > > Get
> > > > Return m_text2
> > > > End Get
> > > > Set(ByVal value As String)
> > > > m_text2 = value
> > > > End Set
> > > > End Property
> > > >
> > > > End Class
> > > >
> > > >
> > > > Public Class PersonForm
> > > > Inherits System.Windows.Forms.Form
> > > >
> > > > ' ... designer generated code
> > > >
> > > > Private aPerson As New Person
> > > >
> > > > Private Sub SamSpadeForm_Load(ByVal sender As Object,
ByVal e
As
> > > > System.EventArgs) Handles MyBase.Load
> > > > Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1")
> > > > Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2")
> > > > End Sub
> > > >
> > > > End Class
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > >
> > > >
> > > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > > > I'm not sure if I'm going down the correct route...
> > > > >
> > > > > I have a class which exposes a number of properties of an

object (in
> > > this
> > > > > case the object represents a customer). Can I then use this > object
> > > to
> > > > > databind to text boxes etc?
> > > > >
> > > > > I can't use a dataset as the object has loads of derived logic, for
> > > > example
> > > > > updating one property may actually update several database

fields
> for
> > > > > example.
> > > > >
> > > > > Hope I've explained this clear enough...
> > > > >
> > > > > Regards
> > > > > Simon
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #15
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
news:us**************@TK2MSFTNGP09.phx.gbl...
If the OP is building an inherited control then custom properties can be
bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
Simon,
As far as I can tell the designer data-binding requires binding to a list
of
items.

I am not aware of any interface that will enable you to bind in the designer
to a single object. Other then Making your single object appear to be a
list, which IMHO is more work then simply adding the data binding
manually...

Considering there is more work on defining the object to support data
binding, then the databinding itself, I personally don't have a problem

with
this.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
Thanks Jay...

I've got it working using the data binding in code...

I'd like to be able to do the data-binding in the designer.... I guess
I
need another interface?

Regards
Simon

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message news:Of**************@TK2MSFTNGP12.phx.gbl...
> Simon,
> As I stated earlier: Correct! you don't need to implement any interfaces if
> you have a single object ("record").
>
> You need to include a Text1Changed event for the Text1 property, if you can
> change the object outside of the form, if only the form can change the > object/property, then the event is not as important.
>
> The "Changed" event needs to be named the same as the property, with
Changed
> as the suffix, as my Person example shows.
>
> Hope this helps
> Jay
>
> "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > So do I read it that I don't need to implement all the interfaces if I
> just
> > have a single record ????
> >
> > Simon
> > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
> > news:ex**************@TK2MSFTNGP09.phx.gbl...
> > > Terry,
> > > > The only problem with this is that if you change the aPerson.Text1 > value
> > > > this is not reflected in the TextBox1
> > > That's because I left out the notification. :-( Here is a
version with
> > > Notifications. :-)
> > >
> > > Public Class Person
> > >
> > > Public Event Text1Changed As EventHandler
> > > Public Event Text2Changed As EventHandler
> > >
> > > Private m_text1 As String
> > > Private m_text2 As String
> > >
> > > Public Sub New()
> > > m_text1 = String.Empty
> > > m_text2 = String.Empty
> > > End Sub
> > >
> > > Public Property Text1() As String
> > > Get
> > > Return m_text1
> > > End Get
> > > Set(ByVal value As String)
> > > m_text1 = value
> > > OnText1Changed(EventArgs.Empty)
> > > End Set
> > > End Property
> > >
> > > Public Property Text2() As String
> > > Get
> > > Return m_text2
> > > End Get
> > > Set(ByVal value As String)
> > > m_text2 = value
> > > OnText2Changed(EventArgs.Empty)
> > > End Set
> > > End Property
> > >
> > > Protected Overridable Sub OnText1Changed(ByVal e As
EventArgs) > > > RaiseEvent Text1Changed(Me, e)
> > > End Sub
> > >
> > > Protected Overridable Sub OnText2Changed(ByVal e As EventArgs) > > > RaiseEvent Text2Changed(Me, e)
> > > End Sub
> > >
> > > End Class
> > >
> > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
> > > changes it in TextBox1!
> > >
> > > I don't have a clear link that explains the above, if you want it or > need
> > it
> > > I can look for it later.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>
wrote
in > > message
> > > news:%2****************@TK2MSFTNGP11.phx.gbl...
> > > > The only problem with this is that if you change the aPerson.Text1 > value
> > > > this is not reflected in the TextBox1
> > > >
> > > > --
> > > >
> > > > OHM ( Terry Burns )
> > > > . . . One-Handed-Man . . .
> > > >
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in > > message
> > > > news:OC**************@TK2MSFTNGP12.phx.gbl...
> > > > > Simon,
> > > > > As OHM suggested, you need to implement IList, ICollection,
> > IEnumerable
> > > if
> > > > > you want to "edit" a list of items. If you have a single
item, you
> do
> > > not
> > > > > need to implement those interfaces.
> > > > >
> > > > > In my experience IEditableObject is useful but not required

to > change
> > > > bound
> > > > > data, if you fully implement IEditableObject you can cancel

the > > change,
> > > > > without IEditableObject the change is made, period.
> > > > >
> > > > > This article appears to be a good starting point on data

binding.
> > > > > http://support.microsoft.com/default...b;en-us;313482 > > > > >
> > > > >
> > > > > Here is a simple sample of binding to an Object:
> > > > >
> > > > > Public Class Person
> > > > >
> > > > > Private m_text1 As String
> > > > > Private m_text2 As String
> > > > >
> > > > > Public Sub New()
> > > > > m_text1 = String.Empty
> > > > > m_text2 = String.Empty
> > > > > End Sub
> > > > >
> > > > > Public Property Text1() As String
> > > > > Get
> > > > > Return m_text1
> > > > > End Get
> > > > > Set(ByVal value As String)
> > > > > m_text1 = value
> > > > > End Set
> > > > > End Property
> > > > >
> > > > > Public Property Text2() As String
> > > > > Get
> > > > > Return m_text2
> > > > > End Get
> > > > > Set(ByVal value As String)
> > > > > m_text2 = value
> > > > > End Set
> > > > > End Property
> > > > >
> > > > > End Class
> > > > >
> > > > >
> > > > > Public Class PersonForm
> > > > > Inherits System.Windows.Forms.Form
> > > > >
> > > > > ' ... designer generated code
> > > > >
> > > > > Private aPerson As New Person
> > > > >
> > > > > Private Sub SamSpadeForm_Load(ByVal sender As Object,

ByVal
e
As
> > > > > System.EventArgs) Handles MyBase.Load
> > > > > Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1") > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2") > > > > > End Sub
> > > > >
> > > > > End Class
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > >
> > > > >
> > > > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > > > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > > > > I'm not sure if I'm going down the correct route...
> > > > > >
> > > > > > I have a class which exposes a number of properties of an

object
> (in
> > > > this
> > > > > > case the object represents a customer). Can I then use

this
> > object
> > > > to
> > > > > > databind to text boxes etc?
> > > > > >
> > > > > > I can't use a dataset as the object has loads of derived

logic,
> for
> > > > > example
> > > > > > updating one property may actually update several database
fields
> > for
> > > > > > example.
> > > > > >
> > > > > > Hope I've explained this clear enough...
> > > > > >
> > > > > > Regards
> > > > > > Simon
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #16
If you want to set a wrapped control's custom property from the designer you
need to add attribute tags. When its added to the form you will see the
custom property, is this what you need ?

IE
<Browsable(True), Category("Appearance")> _

Public Property xxxxx as xxxxxxxx

..

..

..
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
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 news:us**************@TK2MSFTNGP09.phx.gbl...
If the OP is building an inherited control then custom properties can be
bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:up**************@TK2MSFTNGP12.phx.gbl...
Simon,
As far as I can tell the designer data-binding requires binding to a list
of
items.

I am not aware of any interface that will enable you to bind in the designer
to a single object. Other then Making your single object appear to be a list, which IMHO is more work then simply adding the data binding
manually...

Considering there is more work on defining the object to support data
binding, then the databinding itself, I personally don't have a problem with
this.

Hope this helps
Jay

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
> Thanks Jay...
>
> I've got it working using the data binding in code...
>
> I'd like to be able to do the data-binding in the designer.... I

guess
I
> need another interface?
>
> Regards
> Simon
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> news:Of**************@TK2MSFTNGP12.phx.gbl...
> > Simon,
> > As I stated earlier: Correct! you don't need to implement any

interfaces
> if
> > you have a single object ("record").
> >
> > You need to include a Text1Changed event for the Text1 property,
if you
> can
> > change the object outside of the form, if only the form can change the > > object/property, then the event is not as important.
> >
> > The "Changed" event needs to be named the same as the property,
with > Changed
> > as the suffix, as my Person example shows.
> >
> > Hope this helps
> > Jay
> >
> > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > news:%2****************@TK2MSFTNGP10.phx.gbl...
> > > So do I read it that I don't need to implement all the interfaces if
I
> > just
> > > have a single record ????
> > >
> > > Simon
> > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote
in > message
> > > news:ex**************@TK2MSFTNGP09.phx.gbl...
> > > > Terry,
> > > > > The only problem with this is that if you change the

aPerson.Text1
> > value
> > > > > this is not reflected in the TextBox1
> > > > That's because I left out the notification. :-( Here is a

version with
> > > > Notifications. :-)
> > > >
> > > > Public Class Person
> > > >
> > > > Public Event Text1Changed As EventHandler
> > > > Public Event Text2Changed As EventHandler
> > > >
> > > > Private m_text1 As String
> > > > Private m_text2 As String
> > > >
> > > > Public Sub New()
> > > > m_text1 = String.Empty
> > > > m_text2 = String.Empty
> > > > End Sub
> > > >
> > > > Public Property Text1() As String
> > > > Get
> > > > Return m_text1
> > > > End Get
> > > > Set(ByVal value As String)
> > > > m_text1 = value
> > > > OnText1Changed(EventArgs.Empty)
> > > > End Set
> > > > End Property
> > > >
> > > > Public Property Text2() As String
> > > > Get
> > > > Return m_text2
> > > > End Get
> > > > Set(ByVal value As String)
> > > > m_text2 = value
> > > > OnText2Changed(EventArgs.Empty)
> > > > End Set
> > > > End Property
> > > >
> > > > Protected Overridable Sub OnText1Changed(ByVal e As EventArgs) > > > > RaiseEvent Text1Changed(Me, e)
> > > > End Sub
> > > >
> > > > Protected Overridable Sub OnText2Changed(ByVal e As EventArgs) > > > > RaiseEvent Text2Changed(Me, e)
> > > > End Sub
> > > >
> > > > End Class
> > > >
> > > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
> > > > changes it in TextBox1!
> > > >
> > > > I don't have a clear link that explains the above, if you want it
or
> > need
> > > it
> > > > I can look for it later.
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>

wrote
in
> > > message
> > > > news:%2****************@TK2MSFTNGP11.phx.gbl...
> > > > > The only problem with this is that if you change the

aPerson.Text1
> > value
> > > > > this is not reflected in the TextBox1
> > > > >
> > > > > --
> > > > >
> > > > > OHM ( Terry Burns )
> > > > > . . . One-Handed-Man . . .
> > > > >
> > > > >
> > > > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
> > > message
> > > > > news:OC**************@TK2MSFTNGP12.phx.gbl...
> > > > > > Simon,
> > > > > > As OHM suggested, you need to implement IList,
ICollection, > > > IEnumerable
> > > > if
> > > > > > you want to "edit" a list of items. If you have a single

item, you
> > do
> > > > not
> > > > > > need to implement those interfaces.
> > > > > >
> > > > > > In my experience IEditableObject is useful but not required to
> > change
> > > > > bound
> > > > > > data, if you fully implement IEditableObject you can
cancel the
> > > change,
> > > > > > without IEditableObject the change is made, period.
> > > > > >
> > > > > > This article appears to be a good starting point on data
binding.
> > > > > >

http://support.microsoft.com/default...b;en-us;313482 > > > > > >
> > > > > >
> > > > > > Here is a simple sample of binding to an Object:
> > > > > >
> > > > > > Public Class Person
> > > > > >
> > > > > > Private m_text1 As String
> > > > > > Private m_text2 As String
> > > > > >
> > > > > > Public Sub New()
> > > > > > m_text1 = String.Empty
> > > > > > m_text2 = String.Empty
> > > > > > End Sub
> > > > > >
> > > > > > Public Property Text1() As String
> > > > > > Get
> > > > > > Return m_text1
> > > > > > End Get
> > > > > > Set(ByVal value As String)
> > > > > > m_text1 = value
> > > > > > End Set
> > > > > > End Property
> > > > > >
> > > > > > Public Property Text2() As String
> > > > > > Get
> > > > > > Return m_text2
> > > > > > End Get
> > > > > > Set(ByVal value As String)
> > > > > > m_text2 = value
> > > > > > End Set
> > > > > > End Property
> > > > > >
> > > > > > End Class
> > > > > >
> > > > > >
> > > > > > Public Class PersonForm
> > > > > > Inherits System.Windows.Forms.Form
> > > > > >
> > > > > > ' ... designer generated code
> > > > > >
> > > > > > Private aPerson As New Person
> > > > > >
> > > > > > Private Sub SamSpadeForm_Load(ByVal sender As Object,

ByVal
e
> As
> > > > > > System.EventArgs) Handles MyBase.Load
> > > > > > Me.TextBox1.DataBindings.Add("Text", aPerson, "Text1") > > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson, "Text2") > > > > > > End Sub
> > > > > >
> > > > > > End Class
> > > > > >
> > > > > > Hope this helps
> > > > > > Jay
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > > > > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > > > > > I'm not sure if I'm going down the correct route...
> > > > > > >
> > > > > > > I have a class which exposes a number of properties of

an object
> > (in
> > > > > this
> > > > > > > case the object represents a customer). Can I then use this
> > > object
> > > > > to
> > > > > > > databind to text boxes etc?
> > > > > > >
> > > > > > > I can't use a dataset as the object has loads of derived
logic,
> > for
> > > > > > example
> > > > > > > updating one property may actually update several database > fields
> > > for
> > > > > > > example.
> > > > > > >
> > > > > > > Hope I've explained this clear enough...
> > > > > > >
> > > > > > > Regards
> > > > > > > Simon
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #17
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/de...ngpropgrid.asp

http://msdn.microsoft.com/library/de...etpropbrow.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" <ne**@aphroditeuk.com> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
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 news:us**************@TK2MSFTNGP09.phx.gbl...
If the OP is building an inherited control then custom properties can be bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

<<snip>>
Nov 20 '05 #18
I'm not 100% sure how this would help me..

If I exposed all my properties of my class using this method, how would this
help me to bind a text box for example to a property of a specific instance
of this class in the designer???

Or have I totally misunderstood you ??

Thanks in advance!

Simon
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
If you want to set a wrapped control's custom property from the designer you need to add attribute tags. When its added to the form you will see the
custom property, is this what you need ?

IE
<Browsable(True), Category("Appearance")> _

Public Property xxxxx as xxxxxxxx

.

.

.
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
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
news:us**************@TK2MSFTNGP09.phx.gbl...
If the OP is building an inherited control then custom properties can be bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:up**************@TK2MSFTNGP12.phx.gbl...
> Simon,
> As far as I can tell the designer data-binding requires binding to a

list
of
> items.
>
> I am not aware of any interface that will enable you to bind in the
designer
> to a single object. Other then Making your single object appear to be a
> list, which IMHO is more work then simply adding the data binding
> manually...
>
> Considering there is more work on defining the object to support
data > binding, then the databinding itself, I personally don't have a

problem with
> this.
>
> Hope this helps
> Jay
>
> "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> news:O3**************@TK2MSFTNGP10.phx.gbl...
> > Thanks Jay...
> >
> > I've got it working using the data binding in code...
> >
> > I'd like to be able to do the data-binding in the designer.... I guess
> I
> > need another interface?
> >
> > Regards
> > Simon
> >
> > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
> > news:Of**************@TK2MSFTNGP12.phx.gbl...
> > > Simon,
> > > As I stated earlier: Correct! you don't need to implement any
interfaces
> > if
> > > you have a single object ("record").
> > >
> > > You need to include a Text1Changed event for the Text1 property, if you
> > can
> > > change the object outside of the form, if only the form can change the
> > > object/property, then the event is not as important.
> > >
> > > The "Changed" event needs to be named the same as the property, with > > Changed
> > > as the suffix, as my Person example shows.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > news:%2****************@TK2MSFTNGP10.phx.gbl...
> > > > So do I read it that I don't need to implement all the interfaces
if
I
> > > just
> > > > have a single record ????
> > > >
> > > > Simon
> > > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in > > message
> > > > news:ex**************@TK2MSFTNGP09.phx.gbl...
> > > > > Terry,
> > > > > > The only problem with this is that if you change the
aPerson.Text1
> > > value
> > > > > > this is not reflected in the TextBox1
> > > > > That's because I left out the notification. :-( Here is a

version
> with
> > > > > Notifications. :-)
> > > > >
> > > > > Public Class Person
> > > > >
> > > > > Public Event Text1Changed As EventHandler
> > > > > Public Event Text2Changed As EventHandler
> > > > >
> > > > > Private m_text1 As String
> > > > > Private m_text2 As String
> > > > >
> > > > > Public Sub New()
> > > > > m_text1 = String.Empty
> > > > > m_text2 = String.Empty
> > > > > End Sub
> > > > >
> > > > > Public Property Text1() As String
> > > > > Get
> > > > > Return m_text1
> > > > > End Get
> > > > > Set(ByVal value As String)
> > > > > m_text1 = value
> > > > > OnText1Changed(EventArgs.Empty)
> > > > > End Set
> > > > > End Property
> > > > >
> > > > > Public Property Text2() As String
> > > > > Get
> > > > > Return m_text2
> > > > > End Get
> > > > > Set(ByVal value As String)
> > > > > m_text2 = value
> > > > > OnText2Changed(EventArgs.Empty)
> > > > > End Set
> > > > > End Property
> > > > >
> > > > > Protected Overridable Sub OnText1Changed(ByVal e As

EventArgs)
> > > > > RaiseEvent Text1Changed(Me, e)
> > > > > End Sub
> > > > >
> > > > > Protected Overridable Sub OnText2Changed(ByVal e As

EventArgs)
> > > > > RaiseEvent Text2Changed(Me, e)
> > > > > End Sub
> > > > >
> > > > > End Class
> > > > >
> > > > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the > above
> > > > > changes it in TextBox1!
> > > > >
> > > > > I don't have a clear link that explains the above, if you
want it
or
> > > need
> > > > it
> > > > > I can look for it later.
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>

wrote
in
> > > > message
> > > > > news:%2****************@TK2MSFTNGP11.phx.gbl...
> > > > > > The only problem with this is that if you change the
aPerson.Text1
> > > value
> > > > > > this is not reflected in the TextBox1
> > > > > >
> > > > > > --
> > > > > >
> > > > > > OHM ( Terry Burns )
> > > > > > . . . One-Handed-Man . . .
> > > > > >
> > > > > >
> > > > > > "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com>

wrote in
> > > > message
> > > > > > news:OC**************@TK2MSFTNGP12.phx.gbl...
> > > > > > > Simon,
> > > > > > > As OHM suggested, you need to implement IList, ICollection, > > > > IEnumerable
> > > > > if
> > > > > > > you want to "edit" a list of items. If you have a single

item,
> you
> > > do
> > > > > not
> > > > > > > need to implement those interfaces.
> > > > > > >
> > > > > > > In my experience IEditableObject is useful but not required
to
> > > change
> > > > > > bound
> > > > > > > data, if you fully implement IEditableObject you can

cancel the
> > > > change,
> > > > > > > without IEditableObject the change is made, period.
> > > > > > >
> > > > > > > This article appears to be a good starting point on data
> binding.
> > > > > > >

http://support.microsoft.com/default...b;en-us;313482
> > > > > > >
> > > > > > >
> > > > > > > Here is a simple sample of binding to an Object:
> > > > > > >
> > > > > > > Public Class Person
> > > > > > >
> > > > > > > Private m_text1 As String
> > > > > > > Private m_text2 As String
> > > > > > >
> > > > > > > Public Sub New()
> > > > > > > m_text1 = String.Empty
> > > > > > > m_text2 = String.Empty
> > > > > > > End Sub
> > > > > > >
> > > > > > > Public Property Text1() As String
> > > > > > > Get
> > > > > > > Return m_text1
> > > > > > > End Get
> > > > > > > Set(ByVal value As String)
> > > > > > > m_text1 = value
> > > > > > > End Set
> > > > > > > End Property
> > > > > > >
> > > > > > > Public Property Text2() As String
> > > > > > > Get
> > > > > > > Return m_text2
> > > > > > > End Get
> > > > > > > Set(ByVal value As String)
> > > > > > > m_text2 = value
> > > > > > > End Set
> > > > > > > End Property
> > > > > > >
> > > > > > > End Class
> > > > > > >
> > > > > > >
> > > > > > > Public Class PersonForm
> > > > > > > Inherits System.Windows.Forms.Form
> > > > > > >
> > > > > > > ' ... designer generated code
> > > > > > >
> > > > > > > Private aPerson As New Person
> > > > > > >
> > > > > > > Private Sub SamSpadeForm_Load(ByVal sender As
Object, ByVal
> e
> > As
> > > > > > > System.EventArgs) Handles MyBase.Load
> > > > > > > Me.TextBox1.DataBindings.Add("Text", aPerson,

"Text1")
> > > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson,

"Text2")
> > > > > > > End Sub
> > > > > > >
> > > > > > > End Class
> > > > > > >
> > > > > > > Hope this helps
> > > > > > > Jay
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > "Simon Verona" <ne**@aphroditeuk.com> wrote in message
> > > > > > > news:e3**************@TK2MSFTNGP09.phx.gbl...
> > > > > > > > I'm not sure if I'm going down the correct route...
> > > > > > > >
> > > > > > > > I have a class which exposes a number of properties of

an > object
> > > (in
> > > > > > this
> > > > > > > > case the object represents a customer). Can I then use > this
> > > > object
> > > > > > to
> > > > > > > > databind to text boxes etc?
> > > > > > > >
> > > > > > > > I can't use a dataset as the object has loads of derived > logic,
> > > for
> > > > > > > example
> > > > > > > > updating one property may actually update several database > > fields
> > > > for
> > > > > > > > example.
> > > > > > > >
> > > > > > > > Hope I've explained this clear enough...
> > > > > > > >
> > > > > > > > Regards
> > > > > > > > Simon
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #19
Jay

Thats the sort of code I had in mind to add to an "inherited" text box....
As you say I will still need code in the form to set the datasource to the
instance of my object. I was hoping that I could write some code within my
inherited control so that it took the object name as the "datasource" and
internally mapped to the object itself...

The reason I want to do this is that I have a number of data entry forms to
write that are bound to custom classes and it would be much more simple if I
could write it so that I can do it all in the form designer without having
to remember to go back and add code to do the binding...

I'm just trying to make my life more simple by doing the "hard" work once!

Thanks in advance.
Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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/de...ngpropgrid.asp
http://msdn.microsoft.com/library/de...etpropbrow.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" <ne**@aphroditeuk.com> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
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
news:us**************@TK2MSFTNGP09.phx.gbl...
If the OP is building an inherited control then custom properties can

be bound to the properties window with an attribute tag. Maybe that would
help.?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

<<snip>>

Nov 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
2
by: David Veeneman | last post by:
I want to data bind a user control and a business object, using a BindingSource control. The control has a 'Priority' property that takes a 'Priority' enum (High, Normal, Low). The business object...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.