Connecting Tech Pros Worldwide Forums | Help | Site Map

Data Binding to a object...

Simon Verona
Guest
 
Posts: n/a
#1: Nov 20 '05
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



One Handed Man \( OHM - Terry Burns \)
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Data Binding to a object...


As long as your object implements IList, ICollection, IEnumerable then you
should be OK

--

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


"Simon Verona" <news@aphroditeuk.com> wrote in message
news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
example[color=blue]
> updating one property may actually update several database fields for
> example.
>
> Hope I've explained this clear enough...
>
> Regards
> Simon
>
>[/color]


Simon Verona
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Data Binding to a object...


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:eUxNjMeWEHA.716@TK2MSFTNGP11.phx.gbl...[color=blue]
> As long as your object implements IList, ICollection, IEnumerable then you
> should be OK
>
> --
>
> OHM ( Terry Burns )
> . . . One-Handed-Man . . .
>
>
> "Simon Verona" <news@aphroditeuk.com> wrote in message
> news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=green]
> > 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[/color][/color]
this[color=blue][color=green]
> > case the object represents a customer). Can I then use this object[/color][/color]
to[color=blue][color=green]
> > databind to text boxes etc?
> >
> > I can't use a dataset as the object has loads of derived logic, for[/color]
> example[color=green]
> > updating one property may actually update several database fields for
> > example.
> >
> > Hope I've explained this clear enough...
> >
> > Regards
> > Simon
> >
> >[/color]
>
>[/color]


Ken Tucker [MVP]
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Data Binding to a object...


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:eUxNjMeWEHA.716@TK2MSFTNGP11.phx.gbl:[color=blue]
> As long as your object implements IList, ICollection, IEnumerable then you
>
> should be OK
>[/color]

--
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


Ken Tucker [MVP]
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Data Binding to a object...


Hi,

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

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

"Simon Verona" <news@aphroditeuk.com> wrote in message
news:#bxsS7eWEHA.3200@TK2MSFTNGP09.phx.gbl:[color=blue]
> 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:eUxNjMeWEHA.716@TK2MSFTNGP11.phx.gbl...
>[color=green]
> > As long as your object implements IList, ICollection, IEnumerable then
> > you
> > should be OK
> >
> > --
> >
> > OHM ( Terry Burns )
> > . . . One-Handed-Man . . .
> >
> >
> > "Simon Verona" <HYPERLINK
> > "mailto:news@aphroditeuk.com"news@aphroditeuk. com> wrote in message
> > news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[/color]
>[color=green][color=darkred]
> > > 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[/color][/color]
>
> this
>[color=green][color=darkred]
> > > case the object represents a customer). Can I then use this
> > > object[/color][/color]
>
> to
>[color=green][color=darkred]
> > > databind to text boxes etc?
> > >
> > > I can't use a dataset as the object has loads of derived logic, for[/color][/color]
>[color=green]
> > example[/color]
>[color=green][color=darkred]
> > > updating one property may actually update several database fields
> > > for
> > > example.
> > >
> > > Hope I've explained this clear enough...
> > >
> > > Regards
> > > Simon
> > >
> > >[/color]
> >[/color]
>[color=green]
> >[/color]
>[/color]

--
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


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Data Binding to a object...


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" <news@aphroditeuk.com> wrote in message
news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
example[color=blue]
> updating one property may actually update several database fields for
> example.
>
> Hope I've explained this clear enough...
>
> Regards
> Simon
>
>[/color]


One Handed Man \( OHM - Terry Burns \)
Guest
 
Posts: n/a
#7: Nov 20 '05

re: Data Binding to a object...


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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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[/color]
bound[color=blue]
> 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" <news@aphroditeuk.com> wrote in message
> news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=green]
> > 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[/color][/color]
this[color=blue][color=green]
> > case the object represents a customer). Can I then use this object[/color][/color]
to[color=blue][color=green]
> > databind to text boxes etc?
> >
> > I can't use a dataset as the object has loads of derived logic, for[/color]
> example[color=green]
> > updating one property may actually update several database fields for
> > example.
> >
> > Hope I've explained this clear enough...
> >
> > Regards
> > Simon
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#8: Nov 20 '05

re: Data Binding to a object...


Terry,[color=blue]
> The only problem with this is that if you change the aPerson.Text1 value
> this is not reflected in the TextBox1[/color]
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:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...[color=green]
> > Simon,
> > As OHM suggested, you need to implement IList, ICollection, IEnumerable[/color][/color]
if[color=blue][color=green]
> > you want to "edit" a list of items. If you have a single item, you do[/color][/color]
not[color=blue][color=green]
> > need to implement those interfaces.
> >
> > In my experience IEditableObject is useful but not required to change[/color]
> bound[color=green]
> > 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" <news@aphroditeuk.com> wrote in message
> > news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > 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[/color][/color]
> this[color=green][color=darkred]
> > > case the object represents a customer). Can I then use this object[/color][/color]
> to[color=green][color=darkred]
> > > databind to text boxes etc?
> > >
> > > I can't use a dataset as the object has loads of derived logic, for[/color]
> > example[color=darkred]
> > > updating one property may actually update several database fields for
> > > example.
> > >
> > > Hope I've explained this clear enough...
> > >
> > > Regards
> > > Simon
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Simon Verona
Guest
 
Posts: n/a
#9: Nov 20 '05

re: Data Binding to a object...


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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...[color=blue]
> Terry,[color=green]
> > The only problem with this is that if you change the aPerson.Text1 value
> > this is not reflected in the TextBox1[/color]
> 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[/color]
it[color=blue]
> I can look for it later.
>
> Hope this helps
> Jay
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
message[color=blue]
> news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Simon,
> > > As OHM suggested, you need to implement IList, ICollection,[/color][/color][/color]
IEnumerable[color=blue]
> if[color=green][color=darkred]
> > > you want to "edit" a list of items. If you have a single item, you do[/color][/color]
> not[color=green][color=darkred]
> > > need to implement those interfaces.
> > >
> > > In my experience IEditableObject is useful but not required to change[/color]
> > bound[color=darkred]
> > > data, if you fully implement IEditableObject you can cancel the[/color][/color][/color]
change,[color=blue][color=green][color=darkred]
> > > 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" <news@aphroditeuk.com> wrote in message
> > > news:e3kesKdWEHA.4020@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[/color]
> > this[color=darkred]
> > > > case the object represents a customer). Can I then use this[/color][/color][/color]
object[color=blue][color=green]
> > to[color=darkred]
> > > > 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[/color][/color][/color]
for[color=blue][color=green][color=darkred]
> > > > example.
> > > >
> > > > Hope I've explained this clear enough...
> > > >
> > > > Regards
> > > > Simon
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#10: Nov 20 '05

re: Data Binding to a object...


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" <news@aphroditeuk.com> wrote in message
news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...[color=blue]
> So do I read it that I don't need to implement all the interfaces if I[/color]
just[color=blue]
> have a single record ????
>
> Simon
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...[color=green]
> > Terry,[color=darkred]
> > > The only problem with this is that if you change the aPerson.Text1[/color][/color][/color]
value[color=blue][color=green][color=darkred]
> > > this is not reflected in the TextBox1[/color]
> > 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[/color][/color]
need[color=blue]
> it[color=green]
> > I can look for it later.
> >
> > Hope this helps
> > Jay
> >
> > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
> message[color=green]
> > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > The only problem with this is that if you change the aPerson.Text1[/color][/color][/color]
value[color=blue][color=green][color=darkred]
> > > this is not reflected in the TextBox1
> > >
> > > --
> > >
> > > OHM ( Terry Burns )
> > > . . . One-Handed-Man . . .
> > >
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...
> > > > Simon,
> > > > As OHM suggested, you need to implement IList, ICollection,[/color][/color]
> IEnumerable[color=green]
> > if[color=darkred]
> > > > you want to "edit" a list of items. If you have a single item, you[/color][/color][/color]
do[color=blue][color=green]
> > not[color=darkred]
> > > > need to implement those interfaces.
> > > >
> > > > In my experience IEditableObject is useful but not required to[/color][/color][/color]
change[color=blue][color=green][color=darkred]
> > > bound
> > > > data, if you fully implement IEditableObject you can cancel the[/color][/color]
> change,[color=green][color=darkred]
> > > > 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" <news@aphroditeuk.com> wrote in message
> > > > news:e3kesKdWEHA.4020@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[/color][/color][/color]
(in[color=blue][color=green][color=darkred]
> > > this
> > > > > case the object represents a customer). Can I then use this[/color][/color]
> object[color=green][color=darkred]
> > > to
> > > > > databind to text boxes etc?
> > > > >
> > > > > I can't use a dataset as the object has loads of derived logic,[/color][/color][/color]
for[color=blue][color=green][color=darkred]
> > > > example
> > > > > updating one property may actually update several database fields[/color][/color]
> for[color=green][color=darkred]
> > > > > example.
> > > > >
> > > > > Hope I've explained this clear enough...
> > > > >
> > > > > Regards
> > > > > Simon
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#11: Nov 20 '05

re: Data Binding to a object...


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:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...[color=green]
> > Simon,
> > As OHM suggested, you need to implement IList, ICollection, IEnumerable[/color][/color]
if[color=blue][color=green]
> > you want to "edit" a list of items. If you have a single item, you do[/color][/color]
not[color=blue][color=green]
> > need to implement those interfaces.
> >
> > In my experience IEditableObject is useful but not required to change[/color]
> bound[color=green]
> > 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" <news@aphroditeuk.com> wrote in message
> > news:e3kesKdWEHA.4020@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > 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[/color][/color]
> this[color=green][color=darkred]
> > > case the object represents a customer). Can I then use this object[/color][/color]
> to[color=green][color=darkred]
> > > databind to text boxes etc?
> > >
> > > I can't use a dataset as the object has loads of derived logic, for[/color]
> > example[color=darkred]
> > > updating one property may actually update several database fields for
> > > example.
> > >
> > > Hope I've explained this clear enough...
> > >
> > > Regards
> > > Simon
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


One Handed Man \( OHM - Terry Burns \)
Guest
 
Posts: n/a
#12: Nov 20 '05

re: Data Binding to a object...


Thanks, I'll take a read and see what I can learn here !

--

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


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:OU6J7fmWEHA.3012@tk2msftngp13.phx.gbl...[color=blue]
> Terry,
> I found an article that explains binding to an object.
>
>[/color]
http://msdn.microsoft.com/library/de...et02252003.asp[color=blue]
>
> The Design Guidelines for Class Library Developers also discusses the
> events...
>
>[/color]
http://msdn.microsoft.com/library/de...Guidelines.asp[color=blue]
>
> Hope this helps
> Jay
>
> "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
message[color=blue]
> news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Simon,
> > > As OHM suggested, you need to implement IList, ICollection,[/color][/color][/color]
IEnumerable[color=blue]
> if[color=green][color=darkred]
> > > you want to "edit" a list of items. If you have a single item, you do[/color][/color]
> not[color=green][color=darkred]
> > > need to implement those interfaces.
> > >
> > > In my experience IEditableObject is useful but not required to change[/color]
> > bound[color=darkred]
> > > data, if you fully implement IEditableObject you can cancel the[/color][/color][/color]
change,[color=blue][color=green][color=darkred]
> > > 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" <news@aphroditeuk.com> wrote in message
> > > news:e3kesKdWEHA.4020@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[/color]
> > this[color=darkred]
> > > > case the object represents a customer). Can I then use this[/color][/color][/color]
object[color=blue][color=green]
> > to[color=darkred]
> > > > 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[/color][/color][/color]
for[color=blue][color=green][color=darkred]
> > > > example.
> > > >
> > > > Hope I've explained this clear enough...
> > > >
> > > > Regards
> > > > Simon
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Simon Verona
Guest
 
Posts: n/a
#13: Nov 20 '05

re: Data Binding to a object...


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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:OfumZgjWEHA.3512@TK2MSFTNGP12.phx.gbl...[color=blue]
> Simon,
> As I stated earlier: Correct! you don't need to implement any interfaces[/color]
if[color=blue]
> you have a single object ("record").
>
> You need to include a Text1Changed event for the Text1 property, if you[/color]
can[color=blue]
> 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[/color]
Changed[color=blue]
> as the suffix, as my Person example shows.
>
> Hope this helps
> Jay
>
> "Simon Verona" <news@aphroditeuk.com> wrote in message
> news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...[color=green]
> > So do I read it that I don't need to implement all the interfaces if I[/color]
> just[color=green]
> > have a single record ????
> >
> > Simon
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > Terry,
> > > > The only problem with this is that if you change the aPerson.Text1[/color][/color]
> value[color=green][color=darkred]
> > > > 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[/color][/color]
> need[color=green]
> > it[color=darkred]
> > > I can look for it later.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
> > message[color=darkred]
> > > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...
> > > > The only problem with this is that if you change the aPerson.Text1[/color][/color]
> value[color=green][color=darkred]
> > > > this is not reflected in the TextBox1
> > > >
> > > > --
> > > >
> > > > OHM ( Terry Burns )
> > > > . . . One-Handed-Man . . .
> > > >
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...
> > > > > Simon,
> > > > > As OHM suggested, you need to implement IList, ICollection,[/color]
> > IEnumerable[color=darkred]
> > > if
> > > > > you want to "edit" a list of items. If you have a single item, you[/color][/color]
> do[color=green][color=darkred]
> > > not
> > > > > need to implement those interfaces.
> > > > >
> > > > > In my experience IEditableObject is useful but not required to[/color][/color]
> change[color=green][color=darkred]
> > > > bound
> > > > > data, if you fully implement IEditableObject you can cancel the[/color]
> > change,[color=darkred]
> > > > > 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[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > > > 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" <news@aphroditeuk.com> wrote in message
> > > > > news:e3kesKdWEHA.4020@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[/color][/color]
> (in[color=green][color=darkred]
> > > > this
> > > > > > case the object represents a customer). Can I then use this[/color]
> > object[color=darkred]
> > > > to
> > > > > > databind to text boxes etc?
> > > > > >
> > > > > > I can't use a dataset as the object has loads of derived logic,[/color][/color]
> for[color=green][color=darkred]
> > > > > example
> > > > > > updating one property may actually update several database[/color][/color][/color]
fields[color=blue][color=green]
> > for[color=darkred]
> > > > > > example.
> > > > > >
> > > > > > Hope I've explained this clear enough...
> > > > > >
> > > > > > Regards
> > > > > > Simon
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#14: Nov 20 '05

re: Data Binding to a object...


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" <news@aphroditeuk.com> wrote in message
news:O3OnSFqWEHA.3140@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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[/color]
I[color=blue]
> need another interface?
>
> Regards
> Simon
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:OfumZgjWEHA.3512@TK2MSFTNGP12.phx.gbl...[color=green]
> > Simon,
> > As I stated earlier: Correct! you don't need to implement any interfaces[/color]
> if[color=green]
> > you have a single object ("record").
> >
> > You need to include a Text1Changed event for the Text1 property, if you[/color]
> can[color=green]
> > 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[/color]
> Changed[color=green]
> > as the suffix, as my Person example shows.
> >
> > Hope this helps
> > Jay
> >
> > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > So do I read it that I don't need to implement all the interfaces if I[/color]
> > just[color=darkred]
> > > have a single record ????
> > >
> > > Simon
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...
> > > > Terry,
> > > > > The only problem with this is that if you change the aPerson.Text1[/color]
> > value[color=darkred]
> > > > > this is not reflected in the TextBox1
> > > > That's because I left out the notification. :-( Here is a version[/color][/color][/color]
with[color=blue][color=green][color=darkred]
> > > > 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[/color][/color][/color]
above[color=blue][color=green][color=darkred]
> > > > changes it in TextBox1!
> > > >
> > > > I don't have a clear link that explains the above, if you want it or[/color]
> > need[color=darkred]
> > > it
> > > > I can look for it later.
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
> > > message
> > > > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...
> > > > > The only problem with this is that if you change the aPerson.Text1[/color]
> > value[color=darkred]
> > > > > this is not reflected in the TextBox1
> > > > >
> > > > > --
> > > > >
> > > > > OHM ( Terry Burns )
> > > > > . . . One-Handed-Man . . .
> > > > >
> > > > >
> > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
> > > message
> > > > > news:OCEln3fWEHA.3420@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,[/color][/color][/color]
you[color=blue][color=green]
> > do[color=darkred]
> > > > not
> > > > > > need to implement those interfaces.
> > > > > >
> > > > > > In my experience IEditableObject is useful but not required to[/color]
> > change[color=darkred]
> > > > > 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[/color][/color][/color]
binding.[color=blue][color=green][color=darkred]
> > > > > > 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[/color][/color][/color]
e[color=blue]
> As[color=green][color=darkred]
> > > > > > 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" <news@aphroditeuk.com> wrote in message
> > > > > > news:e3kesKdWEHA.4020@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[/color][/color][/color]
object[color=blue][color=green]
> > (in[color=darkred]
> > > > > this
> > > > > > > case the object represents a customer). Can I then use[/color][/color][/color]
this[color=blue][color=green][color=darkred]
> > > object
> > > > > to
> > > > > > > databind to text boxes etc?
> > > > > > >
> > > > > > > I can't use a dataset as the object has loads of derived[/color][/color][/color]
logic,[color=blue][color=green]
> > for[color=darkred]
> > > > > > example
> > > > > > > updating one property may actually update several database[/color][/color]
> fields[color=green][color=darkred]
> > > for
> > > > > > > example.
> > > > > > >
> > > > > > > Hope I've explained this clear enough...
> > > > > > >
> > > > > > > Regards
> > > > > > > Simon
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


One Handed Man \( OHM - Terry Burns \)
Guest
 
Posts: n/a
#15: Nov 20 '05

re: Data Binding to a object...


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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:upKJEKsWEHA.3740@TK2MSFTNGP12.phx.gbl...[color=blue]
> Simon,
> As far as I can tell the designer data-binding requires binding to a list[/color]
of[color=blue]
> items.
>
> I am not aware of any interface that will enable you to bind in the[/color]
designer[color=blue]
> 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[/color]
with[color=blue]
> this.
>
> Hope this helps
> Jay
>
> "Simon Verona" <news@aphroditeuk.com> wrote in message
> news:O3OnSFqWEHA.3140@TK2MSFTNGP10.phx.gbl...[color=green]
> > 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[/color][/color]
guess[color=blue]
> I[color=green]
> > need another interface?
> >
> > Regards
> > Simon
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:OfumZgjWEHA.3512@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Simon,
> > > As I stated earlier: Correct! you don't need to implement any[/color][/color][/color]
interfaces[color=blue][color=green]
> > if[color=darkred]
> > > you have a single object ("record").
> > >
> > > You need to include a Text1Changed event for the Text1 property, if[/color][/color][/color]
you[color=blue][color=green]
> > can[color=darkred]
> > > 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[/color]
> > Changed[color=darkred]
> > > as the suffix, as my Person example shows.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...
> > > > So do I read it that I don't need to implement all the interfaces if[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > just
> > > > have a single record ????
> > > >
> > > > Simon
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...
> > > > > Terry,
> > > > > > The only problem with this is that if you change the[/color][/color][/color]
aPerson.Text1[color=blue][color=green][color=darkred]
> > > value
> > > > > > this is not reflected in the TextBox1
> > > > > That's because I left out the notification. :-( Here is a version[/color][/color]
> with[color=green][color=darkred]
> > > > > 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[/color][/color]
> above[color=green][color=darkred]
> > > > > changes it in TextBox1!
> > > > >
> > > > > I don't have a clear link that explains the above, if you want it[/color][/color][/color]
or[color=blue][color=green][color=darkred]
> > > need
> > > > it
> > > > > I can look for it later.
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...
> > > > > > The only problem with this is that if you change the[/color][/color][/color]
aPerson.Text1[color=blue][color=green][color=darkred]
> > > value
> > > > > > this is not reflected in the TextBox1
> > > > > >
> > > > > > --
> > > > > >
> > > > > > OHM ( Terry Burns )
> > > > > > . . . One-Handed-Man . . .
> > > > > >
> > > > > >
> > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > > news:OCEln3fWEHA.3420@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,[/color][/color]
> you[color=green][color=darkred]
> > > 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[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > change,
> > > > > > > without IEditableObject the change is made, period.
> > > > > > >
> > > > > > > This article appears to be a good starting point on data[/color][/color]
> binding.[color=green][color=darkred]
> > > > > > > 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,[/color][/color][/color]
ByVal[color=blue]
> e[color=green]
> > As[color=darkred]
> > > > > > > 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" <news@aphroditeuk.com> wrote in message
> > > > > > > news:e3kesKdWEHA.4020@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[/color][/color]
> object[color=green][color=darkred]
> > > (in
> > > > > > this
> > > > > > > > case the object represents a customer). Can I then use[/color][/color]
> this[color=green][color=darkred]
> > > > object
> > > > > > to
> > > > > > > > databind to text boxes etc?
> > > > > > > >
> > > > > > > > I can't use a dataset as the object has loads of derived[/color][/color]
> logic,[color=green][color=darkred]
> > > for
> > > > > > > example
> > > > > > > > updating one property may actually update several database[/color]
> > fields[color=darkred]
> > > > for
> > > > > > > > example.
> > > > > > > >
> > > > > > > > Hope I've explained this clear enough...
> > > > > > > >
> > > > > > > > Regards
> > > > > > > > Simon
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Simon Verona
Guest
 
Posts: n/a
#16: Nov 20 '05

re: Data Binding to a object...


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:usOZ1YsWEHA.1656@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:upKJEKsWEHA.3740@TK2MSFTNGP12.phx.gbl...[color=green]
> > Simon,
> > As far as I can tell the designer data-binding requires binding to a[/color][/color]
list[color=blue]
> of[color=green]
> > items.
> >
> > I am not aware of any interface that will enable you to bind in the[/color]
> designer[color=green]
> > 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[/color]
> with[color=green]
> > this.
> >
> > Hope this helps
> > Jay
> >
> > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > news:O3OnSFqWEHA.3140@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > 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[/color][/color]
> guess[color=green]
> > I[color=darkred]
> > > need another interface?
> > >
> > > Regards
> > > Simon
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:OfumZgjWEHA.3512@TK2MSFTNGP12.phx.gbl...
> > > > Simon,
> > > > As I stated earlier: Correct! you don't need to implement any[/color][/color]
> interfaces[color=green][color=darkred]
> > > if
> > > > you have a single object ("record").
> > > >
> > > > You need to include a Text1Changed event for the Text1 property, if[/color][/color]
> you[color=green][color=darkred]
> > > can
> > > > change the object outside of the form, if only the form can change[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > 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" <news@aphroditeuk.com> wrote in message
> > > > news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...
> > > > > So do I read it that I don't need to implement all the interfaces[/color][/color][/color]
if[color=blue]
> I[color=green][color=darkred]
> > > > just
> > > > > have a single record ????
> > > > >
> > > > > Simon
> > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
> > > message
> > > > > news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...
> > > > > > Terry,
> > > > > > > The only problem with this is that if you change the[/color][/color]
> aPerson.Text1[color=green][color=darkred]
> > > > value
> > > > > > > this is not reflected in the TextBox1
> > > > > > That's because I left out the notification. :-( Here is a[/color][/color][/color]
version[color=blue][color=green]
> > with[color=darkred]
> > > > > > 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[/color][/color][/color]
EventArgs)[color=blue][color=green][color=darkred]
> > > > > > RaiseEvent Text1Changed(Me, e)
> > > > > > End Sub
> > > > > >
> > > > > > Protected Overridable Sub OnText2Changed(ByVal e As[/color][/color][/color]
EventArgs)[color=blue][color=green][color=darkred]
> > > > > > RaiseEvent Text2Changed(Me, e)
> > > > > > End Sub
> > > > > >
> > > > > > End Class
> > > > > >
> > > > > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the[/color]
> > above[color=darkred]
> > > > > > changes it in TextBox1!
> > > > > >
> > > > > > I don't have a clear link that explains the above, if you want[/color][/color][/color]
it[color=blue]
> or[color=green][color=darkred]
> > > > need
> > > > > it
> > > > > > I can look for it later.
> > > > > >
> > > > > > Hope this helps
> > > > > > Jay
> > > > > >
> > > > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>[/color][/color][/color]
wrote[color=blue]
> in[color=green][color=darkred]
> > > > > message
> > > > > > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...
> > > > > > > The only problem with this is that if you change the[/color][/color]
> aPerson.Text1[color=green][color=darkred]
> > > > value
> > > > > > > this is not reflected in the TextBox1
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > > OHM ( Terry Burns )
> > > > > > > . . . One-Handed-Man . . .
> > > > > > >
> > > > > > >
> > > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color]
> in[color=green][color=darkred]
> > > > > message
> > > > > > > news:OCEln3fWEHA.3420@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[/color][/color][/color]
item,[color=blue][color=green]
> > you[color=darkred]
> > > > do
> > > > > > not
> > > > > > > > need to implement those interfaces.
> > > > > > > >
> > > > > > > > In my experience IEditableObject is useful but not required[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> > > > change
> > > > > > > bound
> > > > > > > > data, if you fully implement IEditableObject you can cancel[/color][/color]
> the[color=green][color=darkred]
> > > > > change,
> > > > > > > > without IEditableObject the change is made, period.
> > > > > > > >
> > > > > > > > This article appears to be a good starting point on data[/color]
> > binding.[color=darkred]
> > > > > > > >[/color][/color][/color]
http://support.microsoft.com/default...b;en-us;313482[color=blue][color=green][color=darkred]
> > > > > > > >
> > > > > > > >
> > > > > > > > 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,[/color][/color]
> ByVal[color=green]
> > e[color=darkred]
> > > As
> > > > > > > > System.EventArgs) Handles MyBase.Load
> > > > > > > > Me.TextBox1.DataBindings.Add("Text", aPerson,[/color][/color][/color]
"Text1")[color=blue][color=green][color=darkred]
> > > > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson,[/color][/color][/color]
"Text2")[color=blue][color=green][color=darkred]
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > End Class
> > > > > > > >
> > > > > > > > Hope this helps
> > > > > > > > Jay
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > > > > > news:e3kesKdWEHA.4020@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[/color]
> > object[color=darkred]
> > > > (in
> > > > > > > this
> > > > > > > > > case the object represents a customer). Can I then use[/color]
> > this[color=darkred]
> > > > > object
> > > > > > > to
> > > > > > > > > databind to text boxes etc?
> > > > > > > > >
> > > > > > > > > I can't use a dataset as the object has loads of derived[/color]
> > logic,[color=darkred]
> > > > for
> > > > > > > > example
> > > > > > > > > updating one property may actually update several database
> > > fields
> > > > > for
> > > > > > > > > example.
> > > > > > > > >
> > > > > > > > > Hope I've explained this clear enough...
> > > > > > > > >
> > > > > > > > > Regards
> > > > > > > > > Simon
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


One Handed Man \( OHM - Terry Burns \)
Guest
 
Posts: n/a
#17: Nov 20 '05

re: Data Binding to a object...


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" <news@aphroditeuk.com> wrote in message
news:uZBxnctWEHA.3716@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
do[color=blue]
> 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[/color]
message[color=blue]
> news:usOZ1YsWEHA.1656@TK2MSFTNGP09.phx.gbl...[color=green]
> > If the OP is building an inherited control then custom properties can[/color][/color]
be[color=blue][color=green]
> > 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]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:upKJEKsWEHA.3740@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Simon,
> > > As far as I can tell the designer data-binding requires binding to a[/color][/color]
> list[color=green]
> > of[color=darkred]
> > > items.
> > >
> > > I am not aware of any interface that will enable you to bind in the[/color]
> > designer[color=darkred]
> > > to a single object. Other then Making your single object appear to be[/color][/color][/color]
a[color=blue][color=green][color=darkred]
> > > 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[/color][/color][/color]
problem[color=blue][color=green]
> > with[color=darkred]
> > > this.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > news:O3OnSFqWEHA.3140@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[/color]
> > guess[color=darkred]
> > > I
> > > > need another interface?
> > > >
> > > > Regards
> > > > Simon
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:OfumZgjWEHA.3512@TK2MSFTNGP12.phx.gbl...
> > > > > Simon,
> > > > > As I stated earlier: Correct! you don't need to implement any[/color]
> > interfaces[color=darkred]
> > > > if
> > > > > you have a single object ("record").
> > > > >
> > > > > You need to include a Text1Changed event for the Text1 property,[/color][/color][/color]
if[color=blue][color=green]
> > you[color=darkred]
> > > > can
> > > > > change the object outside of the form, if only the form can change[/color][/color]
> the[color=green][color=darkred]
> > > > > object/property, then the event is not as important.
> > > > >
> > > > > The "Changed" event needs to be named the same as the property,[/color][/color][/color]
with[color=blue][color=green][color=darkred]
> > > > Changed
> > > > > as the suffix, as my Person example shows.
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > > news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...
> > > > > > So do I read it that I don't need to implement all the[/color][/color][/color]
interfaces[color=blue]
> if[color=green]
> > I[color=darkred]
> > > > > just
> > > > > > have a single record ????
> > > > > >
> > > > > > Simon
> > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > > news:exmJUrgWEHA.3200@TK2MSFTNGP09.phx.gbl...
> > > > > > > Terry,
> > > > > > > > The only problem with this is that if you change the[/color]
> > aPerson.Text1[color=darkred]
> > > > > value
> > > > > > > > this is not reflected in the TextBox1
> > > > > > > That's because I left out the notification. :-( Here is a[/color][/color]
> version[color=green][color=darkred]
> > > 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[/color][/color]
> EventArgs)[color=green][color=darkred]
> > > > > > > RaiseEvent Text1Changed(Me, e)
> > > > > > > End Sub
> > > > > > >
> > > > > > > Protected Overridable Sub OnText2Changed(ByVal e As[/color][/color]
> EventArgs)[color=green][color=darkred]
> > > > > > > RaiseEvent Text2Changed(Me, e)
> > > > > > > End Sub
> > > > > > >
> > > > > > > End Class
> > > > > > >
> > > > > > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > above
> > > > > > > changes it in TextBox1!
> > > > > > >
> > > > > > > I don't have a clear link that explains the above, if you want[/color][/color]
> it[color=green]
> > or[color=darkred]
> > > > > need
> > > > > > it
> > > > > > > I can look for it later.
> > > > > > >
> > > > > > > Hope this helps
> > > > > > > Jay
> > > > > > >
> > > > > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>[/color][/color]
> wrote[color=green]
> > in[color=darkred]
> > > > > > message
> > > > > > > news:%23EFok9fWEHA.4064@TK2MSFTNGP11.phx.gbl...
> > > > > > > > The only problem with this is that if you change the[/color]
> > aPerson.Text1[color=darkred]
> > > > > value
> > > > > > > > this is not reflected in the TextBox1
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > > OHM ( Terry Burns )
> > > > > > > > . . . One-Handed-Man . . .
> > > > > > > >
> > > > > > > >
> > > > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com>[/color][/color][/color]
wrote[color=blue][color=green]
> > in[color=darkred]
> > > > > > message
> > > > > > > > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...
> > > > > > > > > Simon,
> > > > > > > > > As OHM suggested, you need to implement IList,[/color][/color][/color]
ICollection,[color=blue][color=green][color=darkred]
> > > > > > IEnumerable
> > > > > > > if
> > > > > > > > > you want to "edit" a list of items. If you have a single[/color][/color]
> item,[color=green][color=darkred]
> > > you
> > > > > do
> > > > > > > not
> > > > > > > > > need to implement those interfaces.
> > > > > > > > >
> > > > > > > > > In my experience IEditableObject is useful but not[/color][/color][/color]
required[color=blue]
> to[color=green][color=darkred]
> > > > > change
> > > > > > > > bound
> > > > > > > > > data, if you fully implement IEditableObject you can[/color][/color][/color]
cancel[color=blue][color=green]
> > the[color=darkred]
> > > > > > change,
> > > > > > > > > without IEditableObject the change is made, period.
> > > > > > > > >
> > > > > > > > > This article appears to be a good starting point on data
> > > binding.
> > > > > > > > >[/color][/color]
> http://support.microsoft.com/default...b;en-us;313482[color=green][color=darkred]
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > 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,[/color]
> > ByVal[color=darkred]
> > > e
> > > > As
> > > > > > > > > System.EventArgs) Handles MyBase.Load
> > > > > > > > > Me.TextBox1.DataBindings.Add("Text", aPerson,[/color][/color]
> "Text1")[color=green][color=darkred]
> > > > > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson,[/color][/color]
> "Text2")[color=green][color=darkred]
> > > > > > > > > End Sub
> > > > > > > > >
> > > > > > > > > End Class
> > > > > > > > >
> > > > > > > > > Hope this helps
> > > > > > > > > Jay
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > > > > > > news:e3kesKdWEHA.4020@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[/color][/color][/color]
an[color=blue][color=green][color=darkred]
> > > object
> > > > > (in
> > > > > > > > this
> > > > > > > > > > case the object represents a customer). Can I then[/color][/color][/color]
use[color=blue][color=green][color=darkred]
> > > 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[/color][/color][/color]
database[color=blue][color=green][color=darkred]
> > > > fields
> > > > > > for
> > > > > > > > > > example.
> > > > > > > > > >
> > > > > > > > > > Hope I've explained this clear enough...
> > > > > > > > > >
> > > > > > > > > > Regards
> > > > > > > > > > Simon
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#18: Nov 20 '05

re: Data Binding to a object...


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" <news@aphroditeuk.com> wrote in message
news:uZBxnctWEHA.3716@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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[/color]
do[color=blue]
> 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[/color]
message[color=blue]
> news:usOZ1YsWEHA.1656@TK2MSFTNGP09.phx.gbl...[color=green]
> > If the OP is building an inherited control then custom properties can[/color][/color]
be[color=blue][color=green]
> > bound to the properties window with an attribute tag. Maybe that would
> > help.?
> >
> >
> >
> > --
> >
> > OHM ( Terry Burns )
> > . . . One-Handed-Man . . .
> >[/color][/color]
<<snip>>


Simon Verona
Guest
 
Posts: n/a
#19: Nov 20 '05

re: Data Binding to a object...


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:%23NPtaWuWEHA.1104@TK2MSFTNGP10.phx.gbl...[color=blue]
> If you want to set a wrapped control's custom property from the designer[/color]
you[color=blue]
> 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" <news@aphroditeuk.com> wrote in message
> news:uZBxnctWEHA.3716@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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[/color]
> do[color=green]
> > the mapping in code from within the inherited control?? Or am I being[/color][/color]
too[color=blue][color=green]
> > ambitious????
> >
> >
> > Thanks for all your help so far.
> >
> > Simon
> > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
> message[color=green]
> > news:usOZ1YsWEHA.1656@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > If the OP is building an inherited control then custom properties can[/color][/color]
> be[color=green][color=darkred]
> > > 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]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:upKJEKsWEHA.3740@TK2MSFTNGP12.phx.gbl...
> > > > Simon,
> > > > As far as I can tell the designer data-binding requires binding to a[/color]
> > list[color=darkred]
> > > 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[/color][/color][/color]
be[color=blue]
> a[color=green][color=darkred]
> > > > list, which IMHO is more work then simply adding the data binding
> > > > manually...
> > > >
> > > > Considering there is more work on defining the object to support[/color][/color][/color]
data[color=blue][color=green][color=darkred]
> > > > binding, then the databinding itself, I personally don't have a[/color][/color]
> problem[color=green][color=darkred]
> > > with
> > > > this.
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > news:O3OnSFqWEHA.3140@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....[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > guess
> > > > I
> > > > > need another interface?
> > > > >
> > > > > Regards
> > > > > Simon
> > > > >
> > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
> > > message
> > > > > news:OfumZgjWEHA.3512@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,[/color][/color]
> if[color=green][color=darkred]
> > > you
> > > > > can
> > > > > > change the object outside of the form, if only the form can[/color][/color][/color]
change[color=blue][color=green]
> > the[color=darkred]
> > > > > > object/property, then the event is not as important.
> > > > > >
> > > > > > The "Changed" event needs to be named the same as the property,[/color][/color]
> with[color=green][color=darkred]
> > > > > Changed
> > > > > > as the suffix, as my Person example shows.
> > > > > >
> > > > > > Hope this helps
> > > > > > Jay
> > > > > >
> > > > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > > > news:%23Wp2iWjWEHA.2544@TK2MSFTNGP10.phx.gbl...
> > > > > > > So do I read it that I don't need to implement all the[/color][/color]
> interfaces[color=green]
> > if[color=darkred]
> > > I
> > > > > > just
> > > > > > > have a single record ????
> > > > > > >
> > > > > > > Simon
> > > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color]
> in[color=green][color=darkred]
> > > > > message
> > > > > > > news:exmJUrgWEHA.3200@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[/color]
> > version[color=darkred]
> > > > 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[/color]
> > EventArgs)[color=darkred]
> > > > > > > > RaiseEvent Text1Changed(Me, e)
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > Protected Overridable Sub OnText2Changed(ByVal e As[/color]
> > EventArgs)[color=darkred]
> > > > > > > > RaiseEvent Text2Changed(Me, e)
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > End Class
> > > > > > > >
> > > > > > > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in[/color][/color]
> the[color=green][color=darkred]
> > > > above
> > > > > > > > changes it in TextBox1!
> > > > > > > >
> > > > > > > > I don't have a clear link that explains the above, if you[/color][/color][/color]
want[color=blue][color=green]
> > it[color=darkred]
> > > or
> > > > > > need
> > > > > > > it
> > > > > > > > I can look for it later.
> > > > > > > >
> > > > > > > > Hope this helps
> > > > > > > > Jay
> > > > > > > >
> > > > > > > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>[/color]
> > wrote[color=darkred]
> > > in
> > > > > > > message
> > > > > > > > news:%23EFok9fWEHA.4064@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]" <Jay_Harlow_MVP@msn.com>[/color][/color]
> wrote[color=green][color=darkred]
> > > in
> > > > > > > message
> > > > > > > > > news:OCEln3fWEHA.3420@TK2MSFTNGP12.phx.gbl...
> > > > > > > > > > Simon,
> > > > > > > > > > As OHM suggested, you need to implement IList,[/color][/color]
> ICollection,[color=green][color=darkred]
> > > > > > > IEnumerable
> > > > > > > > if
> > > > > > > > > > you want to "edit" a list of items. If you have a single[/color]
> > item,[color=darkred]
> > > > you
> > > > > > do
> > > > > > > > not
> > > > > > > > > > need to implement those interfaces.
> > > > > > > > > >
> > > > > > > > > > In my experience IEditableObject is useful but not[/color][/color]
> required[color=green]
> > to[color=darkred]
> > > > > > change
> > > > > > > > > bound
> > > > > > > > > > data, if you fully implement IEditableObject you can[/color][/color]
> cancel[color=green][color=darkred]
> > > the
> > > > > > > change,
> > > > > > > > > > without IEditableObject the change is made, period.
> > > > > > > > > >
> > > > > > > > > > This article appears to be a good starting point on data
> > > > binding.
> > > > > > > > > >[/color]
> > http://support.microsoft.com/default...b;en-us;313482[color=darkred]
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > 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[/color][/color][/color]
Object,[color=blue][color=green][color=darkred]
> > > ByVal
> > > > e
> > > > > As
> > > > > > > > > > System.EventArgs) Handles MyBase.Load
> > > > > > > > > > Me.TextBox1.DataBindings.Add("Text", aPerson,[/color]
> > "Text1")[color=darkred]
> > > > > > > > > > Me.TextBox2.DataBindings.Add("Text", aPerson,[/color]
> > "Text2")[color=darkred]
> > > > > > > > > > End Sub
> > > > > > > > > >
> > > > > > > > > > End Class
> > > > > > > > > >
> > > > > > > > > > Hope this helps
> > > > > > > > > > Jay
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > "Simon Verona" <news@aphroditeuk.com> wrote in message
> > > > > > > > > > news:e3kesKdWEHA.4020@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[/color][/color]
> an[color=green][color=darkred]
> > > > object
> > > > > > (in
> > > > > > > > > this
> > > > > > > > > > > case the object represents a customer). Can I then[/color][/color]
> use[color=green][color=darkred]
> > > > this
> > > > > > > object
> > > > > > > > > to
> > > > > > > > > > > databind to text boxes etc?
> > > > > > > > > > >
> > > > > > > > > > > I can't use a dataset as the object has loads of[/color][/color][/color]
derived[color=blue][color=green][color=darkred]
> > > > logic,
> > > > > > for
> > > > > > > > > > example
> > > > > > > > > > > updating one property may actually update several[/color][/color]
> database[color=green][color=darkred]
> > > > > fields
> > > > > > > for
> > > > > > > > > > > example.
> > > > > > > > > > >
> > > > > > > > > > > Hope I've explained this clear enough...
> > > > > > > > > > >
> > > > > > > > > > > Regards
> > > > > > > > > > > Simon
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Simon Verona
Guest
 
Posts: n/a
#20: Nov 20 '05

re: Data Binding to a object...


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]" <Jay_Harlow_MVP@msn.com> wrote in message
news:%23X6euyuWEHA.1128@TK2MSFTNGP10.phx.gbl...[color=blue]
> Simon,
> You do not need an inherited control to bind to an object. You just need[/color]
the[color=blue]
> 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[/color]
better[color=blue]
> 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,[/color]
check[color=blue]
> out the following articles.
>
>[/color]
http://msdn.microsoft.com/library/de...ngpropgrid.asp[color=blue]
>
>[/color]
http://msdn.microsoft.com/library/de...etpropbrow.asp[color=blue]
>
>
> 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[/color]
this[color=blue]
> 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" <news@aphroditeuk.com> wrote in message
> news:uZBxnctWEHA.3716@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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[/color]
> do[color=green]
> > the mapping in code from within the inherited control?? Or am I being[/color][/color]
too[color=blue][color=green]
> > ambitious????
> >
> >
> > Thanks for all your help so far.
> >
> > Simon
> > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in[/color]
> message[color=green]
> > news:usOZ1YsWEHA.1656@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > If the OP is building an inherited control then custom properties can[/color][/color]
> be[color=green][color=darkred]
> > > bound to the properties window with an attribute tag. Maybe that would
> > > help.?
> > >
> > >
> > >
> > > --
> > >
> > > OHM ( Terry Burns )
> > > . . . One-Handed-Man . . .
> > >[/color][/color]
> <<snip>>
>
>[/color]


Closed Thread