Results 1 to 7 of 7

Thread: [RESOLVED] datagridview column

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Resolved [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"

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    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?

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    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.

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: datagridview column

    perfect! thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width