Results 1 to 13 of 13

Thread: [RESOLVED] DataGridViewCheckBoxColumn from SQL bit type

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2013
    Posts
    178

    Resolved [RESOLVED] DataGridViewCheckBoxColumn from SQL bit type

    I am looking for a method to convert a SQL bit column (0, 1, NULL) queried into a DataGridViewCheckBoxColumn without using a loop. I tried:

    VB.NET Code:
    1. Dim cell As DataGridViewCell = New DataGridViewCheckBoxCell()
    2.  
    3.         With DataGridView2
    4.             With .Columns("FLY")
    5.                 .CellTemplate = cell
    6.             End With
    7.         End With

    which resulted in the error: "An unhandled exception of type 'System.InvalidCastException' occurred in System.Windows.Forms.dll. Additional information: Value provided for CellTemplate must be of type System.Windows.Forms.DataGridViewTextBoxCell or derive from it."

    I believe this has to do with the 3 state value of the bit type in the SQL column (0, 1, NULL). I also thought maybe to CAST the SQL value to a text value, but wasn't sure of the syntax. What is the best way to go about this and avoid the loop? Perhaps if the data only had 0,1 then VB.net would automatically convert this to TRUE/FALSE and display the Checkbox in the DataGridView?
    Last edited by Fedaykin; Sep 14th, 2020 at 12:14 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width