R
Ryan
I have user defined control that accepts a data source to do some
custom data binding. When I bind the controls against the
bindingsource, it doesn't work, but if i bind it directly against
datatable object (Dim src), it works just fine. Issue is that using
BindingSource makes it easier to navigate through the bind. In
debugging, I see the correct data in the DataSource property so what
gives?
Private m_bindingSource As BindingSource
Public Property DataSource() As Object Implements
ISignBoardControl.DataSource
Get
Return m_bindingSource.DataSource
End Get
Set(ByVal value As Object)
If value.GetType IsNot
GetType(SignBoard.DataWS.Production) Then
Throw New ArgumentException("Incompatible data source
type")
Return
End If
' Dim src as DataWS.Production.PlanActual = value
(actual
datatable object)
m_bindingSource = New BindingSource(value, "PlanActual")
m_bindingSource.Position = 0
lblHeader.DataBindings.Add("Text", m_bindingSource,
"Part")
lblPlan.DataBindings.Add("Text", m_bindingSource, "Plan")
lblActual.DataBindings.Add("Text", m_bindingSource,
"Actual")
lblEfficiency.DataBindings.Add("Text", m_bindingSource,
"Efficiency")
Dim threadProc As Thread = New Thread(AddressOf
DisplayRecord)
threadProc.Name = "DisplayRecord"
threadProc.IsBackground = True
threadProc.Start()
End Set
End Property
' I use this function to iterate through each available row
Private Sub DisplayRecord()
Const timeout As Integer = 60000
While (Not stopThread)
Try
If m_bindingSource.Count = 0 Then Exit Try
If m_bindingSource.Position < m_bindingSource.Count -
1 Then
m_bindingSource.MoveNext()
Else
m_bindingSource.MoveFirst()
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Thread.Sleep(timeout)
End While
End Sub
custom data binding. When I bind the controls against the
bindingsource, it doesn't work, but if i bind it directly against
datatable object (Dim src), it works just fine. Issue is that using
BindingSource makes it easier to navigate through the bind. In
debugging, I see the correct data in the DataSource property so what
gives?
Private m_bindingSource As BindingSource
Public Property DataSource() As Object Implements
ISignBoardControl.DataSource
Get
Return m_bindingSource.DataSource
End Get
Set(ByVal value As Object)
If value.GetType IsNot
GetType(SignBoard.DataWS.Production) Then
Throw New ArgumentException("Incompatible data source
type")
Return
End If
' Dim src as DataWS.Production.PlanActual = value
(actual
datatable object)
m_bindingSource = New BindingSource(value, "PlanActual")
m_bindingSource.Position = 0
lblHeader.DataBindings.Add("Text", m_bindingSource,
"Part")
lblPlan.DataBindings.Add("Text", m_bindingSource, "Plan")
lblActual.DataBindings.Add("Text", m_bindingSource,
"Actual")
lblEfficiency.DataBindings.Add("Text", m_bindingSource,
"Efficiency")
Dim threadProc As Thread = New Thread(AddressOf
DisplayRecord)
threadProc.Name = "DisplayRecord"
threadProc.IsBackground = True
threadProc.Start()
End Set
End Property
' I use this function to iterate through each available row
Private Sub DisplayRecord()
Const timeout As Integer = 60000
While (Not stopThread)
Try
If m_bindingSource.Count = 0 Then Exit Try
If m_bindingSource.Position < m_bindingSource.Count -
1 Then
m_bindingSource.MoveNext()
Else
m_bindingSource.MoveFirst()
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Thread.Sleep(timeout)
End While
End Sub