C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Binding an InputPanel Checkbox

rated by 0 users
This post has 1 Reply | 0 Followers

Top 75 Contributor
Posts 80
AIBofMASS Posted: Tue, Apr 14 2009 3:22 PM

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?

Top 10 Contributor
Posts 1,645
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) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.