Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Databinding NULL Value To A Checkbox

Posted on 2006-06-30
2
Medium Priority
?
743 Views
Last Modified: 2012-08-13
The Following line works if the value in the database is a 0 or 1
      chkCrown.DataBindings.Add("Checked", dsPipeline, "PipelineDS.Crown")

If a NULL is present then I get:
Object cannot be cast from DBNull to other types.
which seems reasonable.  

I would like the checkbox to go to an
Indeterminate checkstate if a NULL is encountered.  How would I do this?

Cheers

0
Comment
Question by:nebbles
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 1600 total points
ID: 17021326
You could

1)  if your database supports it, include in IIF clause in your SELECT statement to bring over a value of 2 if the actual value is Null.  Then you could bind "CheckState" to the column.

2)  add an expression column to your datatable containing an IIF to return 2 if the actual value is Null.  You could then bind "CheckState" to that expression column.

3)  add handlers to the binding for its .Format and .Parse events and convert Null to 2 in the .Format code and convert 2 back to Null in the .Parse code.  Again, the binding would have to be to "CheckState" but it couldbe on the "raw" column.

Roger
0
 

Expert Comment

by:A91627
ID: 17022220
you could try this out...

SELECT ISNULL(Crown, 0) AS Crown FROM PipelineDS ... in your sql statement.

This will set your checkbox state to unchecked if it is <NULL>.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question