Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Formatting numbers in a datagrid

Formatting numbers in a datagrid

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    j1webb
    wrote on last edited by
    #1

    This seems like it should be simple but I could not find any info anywhere to tell me how to do it. Below is the code I am using in my datagrid and I need to format the number in this cell with ",". When 123456789 is displayed (not entered) it needs to look like this 123,456,789 .Add(New System.Windows.Forms.DataGridTextBoxColumn) With .Item(3) .MappingName = "DriveSize" .HeaderText = "Drive Size" .Width = 115 .NullText = String.Empty End With If I try to put the .format member is the above code I get an error telling me it is not a member the datagrid columns style. I have used the .format before to format money, but I don't know why it won't work here. Can anyone tell me what I need to do to format this cell?

    D 1 Reply Last reply
    0
    • J j1webb

      This seems like it should be simple but I could not find any info anywhere to tell me how to do it. Below is the code I am using in my datagrid and I need to format the number in this cell with ",". When 123456789 is displayed (not entered) it needs to look like this 123,456,789 .Add(New System.Windows.Forms.DataGridTextBoxColumn) With .Item(3) .MappingName = "DriveSize" .HeaderText = "Drive Size" .Width = 115 .NullText = String.Empty End With If I try to put the .format member is the above code I get an error telling me it is not a member the datagrid columns style. I have used the .format before to format money, but I don't know why it won't work here. Can anyone tell me what I need to do to format this cell?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I think your looks for something more like this:

      Dim newColumn As New DataGridColumnStyle
       
      With newColumn
      .MappingName = "DriveSize"
      .HeaderText = "Drive Size"
      .Width = 115
      .NullText = "String.Empty
      .Format = "N"
      End With

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I think your looks for something more like this:

        Dim newColumn As New DataGridColumnStyle
         
        With newColumn
        .MappingName = "DriveSize"
        .HeaderText = "Drive Size"
        .Width = 115
        .NullText = "String.Empty
        .Format = "N"
        End With

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        J Offline
        J Offline
        j1webb
        wrote on last edited by
        #3

        Thank you for your response. I had already been trying to use the .format member but with the way I was coding the columns it would not work. I would get an error telling me it was not a member of that object. I finally tried a different way of coding for the columns (similar to yours) but I had to make other additional changes and I finally got it to work. I appreciate your help. You made me rethink how I was approaching the column coding.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups