Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

formatting a column in datagridview

I am trying to format a column in datagridview to currency.  I have changed the default fomat for the column in the designer, but this does not work. I  have put the code below in the CellFormatting event, but it never executes.  When I put a breakpoint on it, it never debugs.

Please help!

Thanks.
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs)
 
Me.DataGridView1.Columns("PRICE").DefaultCellStyle.Format = "c"
 
End Sub

Open in new window

0
nordicgirl
Asked:
nordicgirl
  • 5
  • 4
  • 3
2 Solutions
 
srikanthreddyn143Commented:
Try keeping it in Load
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
>> Try keeping it in Load
I think you mean to add that code in the form load event, right ?
0
 
srikanthreddyn143Commented:
ya
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
nordicgirlAuthor Commented:
here is the error i get.  i also tried declaring the dataviewgridobject, in the code that is commented out.  same result.
Doc4.doc
0
 
srikanthreddyn143Commented:
Check the datasource for the datagrid and its columns.
0
 
srikanthreddyn143Commented:
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs)
 
Me.DataGridView1.Columns("PRICE").DefaultCellStyle.Format = "c"
 
End Sub

In the above code I observe 2 datagridviews. 1.dataGridView1 2.DataGridView1.

Check it once.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Is "PRICE" the name of the column ? If can have that in the header text BUT could not be the column name.
Check the right name or use the index of the column instead.
0
 
nordicgirlAuthor Commented:
Yes, "PRICE" is the name of the column.  I don't understand what you mean by having it in the header text but not the column name.  Could you explain please?

Thanks.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
For each column you have the headertext and the column name. You can have the name as "Column1" and the headertext shows "Price $".
Have you tried to use the index of the column instead ?
0
 
nordicgirlAuthor Commented:
i tried this, with no results but no errors
Me.DataGridView1.Columns.Item(14).DefaultCellStyle.Format = "c"

Open in new window

0
 
srikanthreddyn143Commented:
You can have like this

Me.DataGridView1.Columns(14).DefaultCellStyle.Format = "c"

try it
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Me.DataGridView1.Columns(14).DefaultCellStyle.Format = "c"

Yeap! that way.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now