?
Solved

formatting a column in datagridview

Posted on 2009-05-04
12
Medium Priority
?
321 Views
Last Modified: 2012-05-06
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
Comment
Question by:nordicgirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24298056
Try keeping it in Load
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24298083
>> Try keeping it in Load
I think you mean to add that code in the form load event, right ?
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24298153
ya
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:nordicgirl
ID: 24298503
here is the error i get.  i also tried declaring the dataviewgridobject, in the code that is commented out.  same result.
Doc4.doc
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24298692
Check the datasource for the datagrid and its columns.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24298784
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24298872
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
 

Author Comment

by:nordicgirl
ID: 24299472
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
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 248 total points
ID: 24299525
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
 

Author Comment

by:nordicgirl
ID: 24299684
i tried this, with no results but no errors
Me.DataGridView1.Columns.Item(14).DefaultCellStyle.Format = "c"

Open in new window

0
 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 252 total points
ID: 24299750
You can have like this

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

try it
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24300084
Me.DataGridView1.Columns(14).DefaultCellStyle.Format = "c"

Yeap! that way.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question