PC Review


Reply
Thread Tools Rate Thread

CheckBox quesion. Work on something other than boolean?

 
 
Woody Splawn
Guest
Posts: n/a
 
      4th Sep 2003
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?



 
Reply With Quote
 
 
 
 
Kevin Yu
Guest
Posts: n/a
 
      4th Sep 2003
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."

 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      4th Sep 2003
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


 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      4th Sep 2003
Hi again,

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

Regards,
Fergus


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding three state checkbox to nullable boolean klachemin@comcast.net Microsoft VB .NET 2 22nd Mar 2008 10:44 PM
checkbox ? boolean, bit and int16 - datasource controls? jobs Microsoft ASP .NET 2 21st Jul 2007 10:51 PM
Forcing Checkbox to Return integer instead of boolean Shane Story Microsoft VB .NET 11 23rd Sep 2006 03:05 AM
convert boolean to checkbox in Item_Bound event hazz Microsoft ASP .NET 6 2nd May 2006 10:06 PM
Re: Boolean database value as checkbox on form? Hugh O'Neill Microsoft Access Forms 1 30th Jul 2003 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 PM.