?
Solved

DataGridView bound to sql dataset displays blank bit/boolean field

Posted on 2009-12-27
12
Medium Priority
?
557 Views
Last Modified: 2013-12-26
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
Comment
Question by:steve2918
  • 6
  • 3
10 Comments
 
LVL 1

Expert Comment

by:Fire-EnigmaX
ID: 26127606
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
 

Author Comment

by:steve2918
ID: 26127647
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
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26130609
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
Independent Software Vendors: 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!

 

Author Comment

by:steve2918
ID: 26130779
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
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26135698
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
 

Author Comment

by:steve2918
ID: 26136005
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
 
LVL 11

Accepted Solution

by:
ROMA CHAUHAN earned 150 total points
ID: 26136206
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
 

Author Comment

by:steve2918
ID: 26136433
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
 

Author Comment

by:steve2918
ID: 26392527
As far as I was concerned this problem was solved and the expert ashould get  his piont I solved as noted above

Steve
0
 

Author Closing Comment

by:steve2918
ID: 31681650

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

839 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