Re: Data Binding to a object...
From: Simon Verona (news_at_aphroditeuk.com)
Date: 06/25/04
- Next message: kingnl: "Finding a position in a binary file"
- Previous message: Lars Netzel: "Calculating Estimated time?"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Jun 2004 11:43:55 +0100
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...
> 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...
> > 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...
> > > Terry,
> > > > The only problem with this is that if you change the aPerson.Text1
> value
> > > > this is not reflected in the TextBox1
> > > That's because I left out the notification. :-( Here is a version with
> > > Notifications. :-)
> > >
> > > Public Class Person
> > >
> > > Public Event Text1Changed As EventHandler
> > > Public Event Text2Changed As EventHandler
> > >
> > > Private m_text1 As String
> > > Private m_text2 As String
> > >
> > > Public Sub New()
> > > m_text1 = String.Empty
> > > m_text2 = String.Empty
> > > End Sub
> > >
> > > Public Property Text1() As String
> > > Get
> > > Return m_text1
> > > End Get
> > > Set(ByVal value As String)
> > > m_text1 = value
> > > OnText1Changed(EventArgs.Empty)
> > > End Set
> > > End Property
> > >
> > > Public Property Text2() As String
> > > Get
> > > Return m_text2
> > > End Get
> > > Set(ByVal value As String)
> > > m_text2 = value
> > > OnText2Changed(EventArgs.Empty)
> > > End Set
> > > End Property
> > >
> > > Protected Overridable Sub OnText1Changed(ByVal e As EventArgs)
> > > RaiseEvent Text1Changed(Me, e)
> > > End Sub
> > >
> > > Protected Overridable Sub OnText2Changed(ByVal e As EventArgs)
> > > RaiseEvent Text2Changed(Me, e)
> > > End Sub
> > >
> > > End Class
> > >
> > > I tested the above in VS.NET 2003, Changing aPerson.Test1 in the above
> > > changes it in TextBox1!
> > >
> > > I don't have a clear link that explains the above, if you want it or
> need
> > it
> > > I can look for it later.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
> > message
> > > news:%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> 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, 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.aspx?scid=kb;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
> > > > 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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: kingnl: "Finding a position in a binary file"
- Previous message: Lars Netzel: "Calculating Estimated time?"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Data Binding to a object..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|