i see that i can use defaultcellstyle.format to format a column but what if i have an number stored as a string "0511" and i want to display it as a integer "511"
Printable View
i see that i can use defaultcellstyle.format to format a column but what if i have an number stored as a string "0511" and i want to display it as a integer "511"
That's not formatting. Formatting takes numbers and displays them as strings, not the other way around. You would have to process the data and display it in a different column.
hmmm. well this is how i'm doing things right now:
so by process the data, do you mean just looping through the data and remove the leading zeros and then display it in a new column? or maybe i should change the data type for that column before i populate the datagridview?Code:Using connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\ResidentCounts.mdb")
Using command As New OleDb.OleDbCommand("SELECT ZIP_CODE, CARRIER_ROUTE_ID, DELIVERY_POINT_RECORD_COUNT FROM tblCDSCarrierRoute WHERE ZIP_CODE = '" & TextBoxZip.Text & "'", connection)
connection.Open()
Using reader As OleDb.OleDbDataReader = command.ExecuteReader()
Dim table As New DataTable
table.Load(reader)
With DataGridView1
.DataSource = table
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = False
.AllowUserToResizeRows = False
.Columns(0).DisplayIndex = 3
.Columns(1).HeaderText = "Zip Code"
.Columns(1).ReadOnly = True
.Columns(2).HeaderText = "Route"
.Columns(2).ReadOnly = True
.Columns(3).HeaderText = "Total"
.Columns(3).ReadOnly = True
End With
End Using 'reader
End Using 'command
End Using 'connection
What is the data type in the database..... It sounds like it should be a number and you have it set to Text
i realize it should be a number but it is stored as a string. it is a text file that i import into an access database like this:
so i can't really store the data as number unless i change the data type after i import the list.Code:sql.CommandText = "SELECT * INTO [tblCDSDeliveryPoint] FROM [Text;DATABASE=C:\CDSConversionV2\data\;HDR=YES].[DeliveryPointRecords.txt]"
sql.ExecuteNonQuery()
If your return set is not large you could format the data in CellFormatting event of your DataGridView
So if the column is 0
Code:If e.ColumnIndex = 0 Then
e.Value = CInt(e.Value)
End If
perfect! thanks!