• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

DataGridView bound to sql dataset displays blank bit/boolean field

Hi I have a DataGridView control that is bound to an SQL dataset a bit/boolean field though is displayed  blank althoughh there is a boolean object behind it. How do I get the boolean to display properly
0
steve2918
Asked:
steve2918
  • 6
  • 3
1 Solution
 
Fire-EnigmaXCommented:
I assume you want the boolean to display as a checkbox being checked/unchecked depending on the value in the db cell?

On your gridview in Design Mode, click on the > tag at the top corner of the gridview and then select "Edit Columns" this should open a dialog showing all the fields bound to your dataset (unless you have the "Auto-Generate fields" option selected in which case you may need a slightly different angle to answer this question?)

Now select the "CheckBoxField" option from the top left panel of te dialog and click "Add"
Now click on your newly added field in the bottom-left panel - this will load the properties in the righthand panel now.
In the right-hand panel, look for the option "DataField" and enter the name of the field you want to map to in your sql statement being used to bind to this gridview.
Click OK - and that should be you done

Hope this helps


0
 
steve2918Author Commented:
Hi Thanks for your responce
Unfortuately I am auto generatiing the columns as I want to use the form to display variouse search results from different pionts in the program, code is:
        Dim myDataTable As New DataTable
        Dim MyBindingSource As New BindingSource
        myDataTable.Load(CommonData.Common.DataReader)
        MyBindingSource.DataSource = myDataTable
        DataGridView1.DataSource = MyBindingSource
I cannot finf the "> tag " but presume this is because of the ay I'm generating the binding, lokk forwrd to your further advice
0
 
ROMA CHAUHANProject LeadCommented:
Try this function......

  Sub GetDataFromSql()
        Dim sqlCon As New SqlConnection("Data Source=ROMA\ROMA; Initial Catalog=TestDb; User Id=roma; Password= roma123")
        sqlCon.Open()
        Dim sqlAdpt As New SqlDataAdapter("SELECT * FROM trip_data", sqlCon)
        Dim myDataTable As New DataTable
        sqlAdpt.Fill(myDataTable)
        sqlAdpt.Dispose()
        sqlCon.Close()
        Dim MyBindingSource As New BindingSource
        MyBindingSource.DataSource = myDataTable
        DataGridView1.DataSource = MyBindingSource
    End Sub
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
steve2918Author Commented:
Hi
Thanks for your comment unfortunately the boolean column is still not showing anything.

I am attaching a screen shot of the result its the VOR column on the right that is blank

I adapted the code to fit into program but only as necessary|:

 Dim sqlCon As New SqlConnection("Data Source=SERVER\ASSERVER;DataBase=Parts;Integrated Security=SSPI;")
        sqlCon.Open()
        Dim sqlAdpt As New SqlDataAdapter("SELECT * FROM SalesInvoicesHeaders", sqlCon)
        Dim myDataTable As New DataTable
        sqlAdpt.Fill(myDataTable)
        sqlAdpt.Dispose()
        sqlCon.Close()
        Dim MyBindingSource As New Windows.Forms.BindingSource
        MyBindingSource.DataSource = myDataTable
        DataGridView1.DataSource = MyBindingSource
VOR.JPG
0
 
ROMA CHAUHANProject LeadCommented:
can u post the structure of your table please? so i can get the more idea.
make sure in the database the column type is "bit".
0
 
steve2918Author Commented:
Hi
Here is the structure of the table, the field we are talking about is VOROrder at the bottom:
CREATE TABLE [dbo].[SalesInvoicesHeaders](
      [AutoNumber] [int] IDENTITY(1,1) NOT NULL,
      [CurrentRecord] [bit] NOT NULL,
      [Company] [tinyint] NOT NULL,
      [Depot] [tinyint] NOT NULL,
      [OrderNumber] [int] NOT NULL,
      [CustomerNumber] [int] NOT NULL,
      [InvoiceNumber] [int] NOT NULL,
      [OrderDate] [datetime] NOT NULL,
      [InvoiceDate] [datetime] NOT NULL,
      [CarriageNet] [money] NOT NULL,
      [CarriageVat] [money] NOT NULL,
      [NetTotal] [money] NOT NULL,
      [VAT] [money] NOT NULL,
      [GrossTotal] [money] NOT NULL,
      [TermsCode] [tinyint] NOT NULL,
      [VOROrder] [bit] NOT NULL,
      [AuditNo] [int] NOT NULL
) ON [PRIMARY]
0
 
ROMA CHAUHANProject LeadCommented:
I have checked this in my machine its working fine.
Try one thing... delete the existing grid. Drag and Drop the new DataGridView from toolbox. And paste the code which i have posted u before and tell me will it working or not??
0
 
steve2918Author Commented:
Hi
Got it, I had set the Row Template Hieght to 15, there must not have been enough height to display the checkbox.

thanks for your help roma
0
 
steve2918Author Commented:
As far as I was concerned this problem was solved and the expert ashould get  his piont I solved as noted above

Steve
0
 
steve2918Author Commented:

Got it, I had set the Row Template Hieght to 15, there must not have been enough height to display the checkbox.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now