Option Strict On
Option Explicit On
Imports System
Imports System.Windows.Forms
<System.ComponentModel.DesignerCategory("")> _
Public Class BindingSourcePlus
Inherits BindingSource
#Region ".ctors"
Public Sub New()
'
End Sub
Public Sub New(ByVal components As System.ComponentModel.IContainer)
MyBase.New(components)
End Sub
#End Region
#Region "UI thread sensitive ListChanged invoke"
Private m_Host As Control
''' <summary>
''' Get/Set the Host control to allow the Bindingsource to marshal LsitChanged events to the UI thread
''' </summary>
''' <value>the containing control or Form</value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Host() As Control
Get
Return m_Host
End Get
Set(ByVal value As Control)
m_Host = value
End Set
End Property
Protected Overrides Sub OnListChanged(ByVal e As System.ComponentModel.ListChangedEventArgs)
Dim cntl As Control = Me.Host
If cntl IsNot Nothing AndAlso cntl.InvokeRequired Then
cntl.Invoke(New OnListChangedDelegate(AddressOf OnListChanged), e)
Else
MyBase.OnListChanged(e)
End If
End Sub
Private Delegate Sub OnListChangedDelegate(ByVal e As System.ComponentModel.ListChangedEventArgs)
#End Region
#Region "cornstarch implementation see: http://msmvps.com/blogs/bill/archive/2005/10/05/69012.aspx"
Private m_ReadValuesOnChange As Boolean
Public Property ReadValuesOnChange() As Boolean
Get
Return m_ReadValuesOnChange
End Get
Set(ByVal value As Boolean)
m_ReadValuesOnChange = value
End Set
End Property
Protected Overrides Sub OnBindingComplete(ByVal e As System.Windows.Forms.BindingCompleteEventArgs)
If m_ReadValuesOnChange Then
e.Binding.ReadValue()
End If
MyBase.OnBindingComplete(e)
End Sub
#End Region
End Class