0

i have a datagridview the contents are as follows when i load the datagridview

enter image description here

for the column Payment ID i want the IDs to be like P00001 i know i have to use the mask \P99999 but the question is how? any help would be appreciated thanks in advance.. and the input mask in the access database from where i'm importing the data is \P99999;;#

asdf
  • 460
  • 1
  • 10
  • 31

1 Answers1

1

E.g.

Dim table As New DataTable

With table.Columns
    .Add("Formatted", GetType(Integer))
    .Add("Unformatted", GetType(Integer))
End With

With table.Rows
    .Add(1, 1)
    .Add(2, 2)
    .Add(3, 3)
End With

Me.DataGridView1.DataSource = table
Me.DataGridView1.Columns(0).DefaultCellStyle.Format = "\P00000"
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • The code does work. I ran it myself and observed the intended outcome. If it doesn't for you then you did it wrong. If you're not going to provide any more information than "it doesn't work" then I'm not going to help any further because I'm not about to guess what the issue is. – jmcilhinney Feb 04 '14 at 08:57
  • i have a database (access database) there the input mask is 'P99999' but when i import the data in the grid view i get the one i showed in the picture above but i want it to be 'P00001' is that enough or i have to give you more info.. ? – asdf Feb 04 '14 at 09:03
  • and by the way your code only works when there is no datasource in the gridview does that help... – asdf Feb 04 '14 at 09:11
  • 2
    Are you serious? How can my code only work when there's no data source when my explicitly sets the DataSource property? Have you run my code EXACTLY as it is? If not then how can you say it doesn't work? If your interpretation of my code doesn't work then it's your code that's the issue, not mine. Having said that, what is the data type of your column? As you can clearly see, my code uses Integers. If your data is Strings then formatting is irrelevant because you can't format Strings. You can only format numbers and the like when you convert them to Strings. – jmcilhinney Feb 04 '14 at 09:44