CornStarch - a fixative for Windows Forms Databinding in 2005

Posted Wed, Oct 5 2005 21:29 by bill

I was reading Rocky's post about a work around for a binding issue in VS 2005.  The problem is the field being changed doesn't get updated in the display.    The work around is good, but seems like too much work, so I wrote a component that extends the BindingSource components --> CornStarch  .  As the name implies it helps the binding glue

Usage:  build this component//add it to your project then drag and drop it onto the form in question.  Next select each BindingSource component and set the ReadValuesOnchange extension property to True to apply the fix, or False if you don't want the fix.

Option Strict On

Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Windows.Forms

<DesignerCategory("")> _
<ProvideProperty("ReadValuesOnChange", GetType(BindingSource))> _
Public Class CornStarch
    Inherits System.ComponentModel.Component
    Implements IExtenderProvider

    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
    End Sub

    Public Function CanExtend(ByVal extendee As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf extendee Is BindingSource Then Return True
    End Function

    Public Function GetReadValuesOnChange(ByVal source As BindingSource) As Boolean
        If m_Sources.ContainsKey(source) Then
            Return m_Sources.Item(source)
            Return False
        End If
    End Function

    Public Sub SetReadValuesOnChange(ByVal source As BindingSource, ByVal value As Boolean)
        If m_Sources.ContainsKey(source) Then
            m_Sources.Item(source) = value
            m_Sources.Add(source, value)
        End If
        If value Then
            AddHandler source.BindingComplete, AddressOf Source_BindingComplete
            RemoveHandler source.BindingComplete, AddressOf Source_BindingComplete
        End If
    End Sub

    Private Sub Source_BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs)
    End Sub

    Private m_Sources As New Dictionary(Of BindingSource, Boolean)

End Class


Filed under: ,


# Windows Forms binding issue: A component solution

Wednesday, October 05, 2005 1:49 PM by TrackBack

# BindingSource blues

Monday, July 31, 2006 11:19 PM by @ Head

I've run into yet another problem with BindingSource. As you probably know, Windows.Forms Controls don't...