How to Bind Class object that contains a subclass

  • Thread starter Thread starter Rinso
  • Start date Start date
R

Rinso

Guest
Hi,

I have a Class object "Job" that contains a subclass "ClsPoints".

Public Class Job

Public Property JobName() As String

Public Property JobDescription() As String

Public Property JobLocation() As ClsPoints

End Class

<Public Class ClsPoints

Implements ICloneable
Implements IEnumerable


#Region "Constructors"

Public Sub New()

End Sub

#End Region

#Region "Properties"
Public Property Latitude() as Double

Public Property Longitude() as Double

#End Region

#Region "Methods"

Public Function Clone() As Object Implements System.ICloneable.Clone
Return Me.MemberwiseClone
End Function

Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
Try
Return Me.GetEnumerator
Catch ex As Exception
MessageBox.Show("Error : " & ex.Message, "GetEnumerator", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try

End Function

#End Region

End Class

and wish to Bind the value of Job.JobLocation.Latitude to a textbox.


I have a created a Bindingsource and set its DAtaSource as follows.

Private JobBindingSource As New BindingSource

Private Sub Job_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
UpdatingFlag = False

currentJob = New Job
JobBindingSource.DataSource = currentJob



when I run the code to set the binding

TxtLatitude.DataBindings.Add("text", JobBindingSource, "JobLocation.Lat")

I get the error message below.

1469608.pngIs there a way to bind a subclass or a method to not throw the error?

Thanks,

Rinso

Continue reading...
 
Back
Top