CheckBox quesion. Work on something other than boolean?

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

Just wondering if a checkbox field is designed to work on anything other
than a boolean type field. If not fine, I just need to know. I have many
fields in a SQL Server 2000 table that are Var fields with a width of 1.
These fields contain a Y or an N or a Null. Looks like I may need to
convert these fields to Bit fields if I want them to work with Checkboxes in
VS.net.

Is this correct?
 
Hi Woody,

A Checkbox's Checked property can not be bound to anything other than a
Boolean field of a data source. This is to ensure .net's type-safe feature.

If you want to bind its value to other types, you have to write a Subclass
of Checkbox. Here's an example. The CheckStr property can be bound to a
String field.

Public Class clsCheckBox
Inherits CheckBox
Public Property CheckedStr()
Get
If Checked Then
Return "Y"
Else
Return "N"
End If
End Get
Set(ByVal Value)
If Value.ToString() = "Y" Then
Checked = True
Else
Checked = False
End If
End Set
End Property
End Class

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Woody,

I don't know what you mean by "checkbox field", but the WinForms CheckBox
requires a value from the enum CheckState, ie. CheckState.Checked,
CheckState.Indeterminate or CheckState.Unchecked - it won't even accept True!
(but it will allow False as this matches Unchecked).

In answer to your earlier RadioButton question, and perhaps to what you
want with your CheckBoxes, I suggest that you have hidden Controls that you
<know> will accept your data, eg a TextBox. These Controls can then handle
their change event and set their "partner" Control accordingly.

Hope this helps - I can see your frustration :-).

Regards,
Fergus
 
Hi again,

Oops. I'm thinking of CheckState (3-state checkboxes). For Boolean,
there's plain old Checked, of course.

Regards,
Fergus
 
Back
Top