Solved

Databinding NULL Value To A Checkbox

Posted on 2006-06-30
2
728 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now