Solved

Databinding NULL Value To A Checkbox

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 43
how to make search between pages 17 60
Best book for Internet security 4 55
VB.NET Parsing UDP Bytes 15 38
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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