Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 174703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:34:11+00:00 2026-05-11T13:34:11+00:00

Say I have a DataGridView (named dataGridView ) that is displaying a Strongly Typed

  • 0

Say I have a DataGridView (named dataGridView) that is displaying a Strongly Typed DataTable (named ChildDataTable).

dataGridView has a DataGridViewCheckBoxColumn (named parentIDColumn) that is bound to a Field Property ParentID on each ChildDataRow in ChildDataTable.

ParentID is a foreign key that relates ChildDataTable to another DataTable in the DataSet (creatively named ParentDataTable). In this case, a child may have only one parent. ParentID (and the related ParentDataTable.ID) field are of type Guid.

ChildDataTable.ParentID allows nulls. A null value represents that the child is ‘disconnected’ from any parent, and I want this to display in dataGridView as an unchecked CheckBox in column parentIDColumn (labeled ‘Has Parent’ for clarification purposes).

I have tried manipulating the TrueValue and FalseValue properties on parentIDColumn by creating custom types that implement equality and comparison operations:

    public class NotDBNull : IComparable     {         public override bool Equals(object obj)         {             return !obj.Equals(DBNull.Value);         }          public override int GetHashCode()         {             return Guid.Empty.GetHashCode();         }          public int CompareTo(object obj)         {             return Equals(obj) ? 0 : 1;         }     }      public class IsDBNull : IComparable     {         public override bool Equals(object obj)         {             return obj.Equals(DBNull.Value);         }          public override int GetHashCode()         {             return DBNull.Value.GetHashCode();         }          public int CompareTo(object obj)         {             return Equals(obj) ? 0 : 1;         }     } 

…and then setting them as the True/False values on parentIDColumn:

        parentIDColumn.TrueValue = new NotDBNull();         parentIDColumn.FalseValue = new IsDBNull(); 

But the debugger never hits my breakpoint, suggesting that I have missed the boat. I get the following error upon display of dataGridView:

--------------------------- DataGridView Default Error Dialog --------------------------- The following exception occurred in the DataGridView:  System.FormatException: Value '39df7d96-941a-4be9-a883-03182363bbab' cannot be converted to type 'Boolean'.    at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue)    at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)    at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)  To replace this default dialog please handle the DataError event. --------------------------- OK    --------------------------- 

So I know that my customization is not getting reached. The format call seems to happen on a cell level (rather than column), so I wasn’t sure if there was a better/different way that I was missing.

How do i inject my True/False logic for the checkbox column so that checked means the foreign key is not null, and unchecked means it is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:34:12+00:00Added an answer on May 11, 2026 at 1:34 pm

    Took a bit, but I now have a workable solution.

    I added a new computed column (named HasParent) to ChildDataTable that used the expression ‘ParentID IS NOT NULL’ and was of a Boolean type. Once bound to parentIDColumn, this worked perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView that is bound to a DataTable, it has a column
Say I have a DataGridView Control, this grid is filled through a DataTable. Now,
Let's say I have a DataGridView Control that displays about 100 records of a
I have a WinForms application with DataGridView control. My control has five columns (say
Say I have a DataGridView in which I dynamically build up a ComboBox column
Say I have class A and class B. class A has just a main
Say I have an ASMX web service, MyService. The service has a method, MyMethod.
Say I have a class named Frog, it looks like: public class Frog {
[Note : I've simplified my example for clarity] Let's say that I have a
Say I have a datagridview filled with rows. Now to make certain data more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.