Formatting numbers in a datagrid
-
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?
-
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?
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 WithRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
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 WithRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
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.