Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Databinding NULL Value To A Checkbox

Posted on 2006-06-30
2
Medium Priority
?
737 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

715 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