Solved

Databinding NULL Value To A Checkbox

Posted on 2006-06-30
2
729 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 400 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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