|
-
Apr 5th, 2010, 08:31 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] datagridview column
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"
-
Apr 5th, 2010, 08:47 AM
#2
Re: datagridview column
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.
-
Apr 5th, 2010, 09:00 AM
#3
Thread Starter
Fanatic Member
Re: datagridview column
hmmm. well this is how i'm doing things right now:
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
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?
-
Apr 5th, 2010, 09:01 AM
#4
Re: datagridview column
What is the data type in the database..... It sounds like it should be a number and you have it set to Text
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Apr 5th, 2010, 09:04 AM
#5
Thread Starter
Fanatic Member
Re: datagridview column
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:
Code:
sql.CommandText = "SELECT * INTO [tblCDSDeliveryPoint] FROM [Text;DATABASE=C:\CDSConversionV2\data\;HDR=YES].[DeliveryPointRecords.txt]"
sql.ExecuteNonQuery()
so i can't really store the data as number unless i change the data type after i import the list.
-
Apr 5th, 2010, 12:47 PM
#6
Re: datagridview column
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
-
Apr 5th, 2010, 12:53 PM
#7
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|