Jimbo99999
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
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
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
ASKER
Where do I call the CellFormatting routine from?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
ASKER
'************************'
'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
Did your issue get resolved?
ASKER
I was able to rid the extra row by using:
dgrdGetBills.AllowUserToAd dRows = False
So now I do not have the extra row.
Thanks for helping,
jimbo99999
dgrdGetBills.AllowUserToAd
So now I do not have the extra row.
Thanks for helping,
jimbo99999
Can I see your DataGridView? and how you have formatted the columns