Link to home
Start Free TrialLog in
Avatar of Jimbo99999
Jimbo99999Flag for United States of America

asked on

VB.Net - SQL Table Data 0 Showing as False in DataGrid

Good Day Experts!  Hope all is well with everyone.

I have never experienced or dealt with the dilema that I have at the moment.  

I Query my SQL table and load the results into a DataGridView via a comman/adapter.  The data in the SQL table is 0 or 1. I am grabbing all the 0's.  

In my DataGridView the 0's are showing as False.  The field in the Table is defined a bit.

How can I get it to show as a 0 in my DataGridView?

Thanks,
jimbo99999
Avatar of YZlat
YZlat
Flag of United States of America image

format the column.

Can I see your DataGridView? and how you have formatted the columns
There is a CellFormatting event you could use
try something like that:

Private Sub dataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs)
	Dim grid As DataGridView = DirectCast(sender, DataGridView)
	If grid.Columns(e.ColumnIndex).Name = "your column name" Then
		e.Value = If(CBool(e.Value), "1", "0")
		e.FormattingApplied = True
	End If
End Sub

Open in new window

Avatar of Jimbo99999

ASKER

Where do I call the CellFormatting routine from?
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I have this implemented.  However, I am getting an extra row after my data in the GridView that just has a 0 in this column.  Do you know how I get this to stop happening?
can you post the code you use to load data into your grid?
            '************************'
            'Assign connection string'
            '************************'
            SQLConnect = New System.Data.SqlClient.SqlConnection(SQLConnectConnStringProdEDI)
            '***********************************************************'
            '1)Build SqlCommand to Select EDI Bills from EDI Bills table'
            '2)Open SQL connection                                      '
            '***********************************************************'
            cmdGetEDIBills = New SqlCommand("Select [TRANSFERRED],[ITS CODE],[APPLICATION RECEIVERS CODE]," & _
                                            "SCAC, [PRO NUMBER],[BOL NUMBER],[PAYMENT METHOD]," & _
                                            "[BILLING DATE],[NET AMOUNT DUE],[DELIVERY DATE]," & _
                                            "[PICKUP DATE],[TRANSACTION CONTROL NUMBER],[GROUP CONTROL NUMBER] " & _
                                            "from [INVOICE HEADER] " & _
                                            "where [Transferred] = '0' and ([Billing Date] > GetDate() - 180) " & _
                                            "Order by [Billing Date] desc", SQLConnect)

            SQLConnect.Open()
            '*******************************************************************************'
            'DataAdapter to load data into DataTable "tblGetEDIBillsTable". The DataAdapater' 
            'manages() the flow of data between a DataSet and the Database.                 '
            '*******************************************************************************'
            adapterGetEDIBills = New SqlDataAdapter(cmdGetEDIBills)
            adapterGetEDIBills.Fill(tblGetEDIBillsTable)
            '*****************************************************'
            'Set btnGetAuthTable as dataSource to the dgrdCurrAuth'
            '*****************************************************'
            dgrdGetBills.AutoGenerateColumns = False
            dgrdGetBills.DataSource = tblGetEDIBillsTable
            '***************************************************************************************'
            'In order to center the column headings, a new DataGridViewCellStyle class needs created'
            'and assigned to the ColumHeaderDefaultCellStyle property.                              '
            '***************************************************************************************'
            Dim dgvColumnHeaderStyle As New DataGridViewCellStyle()
            dgvColumnHeaderStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            dgrdGetBills.ColumnHeadersDefaultCellStyle = dgvColumnHeaderStyle
            dgrdGetBills.Rows(0).Selected = False

Open in new window

Did your issue get resolved?
I was able to rid the extra row by using:

dgrdGetBills.AllowUserToAddRows = False

So now I do not have the extra row.

Thanks for helping,
jimbo99999