Binding an InputPanel Checkbox

WinForms

ComponentOne's WinForms controls

Binding an InputPanel Checkbox

  • rated by 0 users
  • This post has 1 Reply |
  • 0 Followers
  • I have a database field that is Y/N.

    Is it possible to specify via properties/bindings that a checkbox should interpret these values or am I better off with an unbound checkbox?

  • Hi,

    Yes. You can bind a checkbox to such a field.

    Instead of

    inputCheckBox1.DataBindings.Add(new Binding("BoundValue", bindingSource1, "MyFieldName"))

    you will have to use something like

    Dim b As Binding = New Binding ("BoundValue", bindingSource1, "MyFieldName", True)
    AddHandler b.Format, AddressOf ConvertTextToBoolean
    AddHandler b.Parse, AddressOf ConvertBooleanToText
    inputCheckBox1.DataBindings.Add(b)

    ConvertTextToBoolean and ConvertBooleanToText are event handlers which
    convert the value from char/string to boolean and vice versa. For example:

    Private Sub ConvertTextToBoolean(sender As Object, cevent As ConvertEventArgs)

    If TypeOf cevent.Value Is String Then
    If CType(cevent.Value, String) = "Y" Then
    cevent.Value = True
    Else
    cevent.Value = False
    End If
    End If

    End Sub

    Private Sub ConvertBooleanToText(sender As Object, cevent As ConvertEventArgs)

    If TypeOf cevent.Value Is Boolean Then
    If CType(cevent.Value, Boolean) = True Then
    cevent.Value = "Y"
    Else
    cevent.Value = "N"
    End If
    End If

    End Sub

    Here we suppose that cevent.Value can be equal to DBNull.Value.

    Hope this will help.

    Regards,

    -Andrey
Page 1 of 1 (2 items)