Binding between objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm desperate! :-/.

I'm desperately trying to bind to objects together to share same data and to display it in a windows forms.

I'm trying to bind an custom object to custom control property. I do have integer selectionid "targetid" in my control and I'm trying to bind the (int) selectionid "sourceid" from my custom data source.

How can it be done? I've tried the following with no luck:

control.DataBindings.Add( "targetId", myCustData, "sourceId" );

How can this be achieved? Please help. Thanks in advance.
 
Antero,
I'm desperately trying to bind to objects together to share
same data and to display it in a windows forms.

I'm trying to bind an custom object to custom control
property. I do have integer selectionid "targetid" in
my control and I'm trying to bind the (int) selectionid
"sourceid" from my custom data source.

The following article covers binding objects to controls.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp

Here is a (VB.NET) sample binding to multiple properties, 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


Public Class PersonForm
Inherits System.Windows.Forms.Form

' ... designer generated code

Private aPerson As New Person

Private Sub Person_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


Antero said:
I'm desperate! :-/.

I'm desperately trying to bind to objects together to share same data and
to display it in a windows forms.
I'm trying to bind an custom object to custom control property. I do have
integer selectionid "targetid" in my control and I'm trying to bind the
(int) selectionid "sourceid" from my custom data source.
 
Back
Top