Solved

formatting a column in datagridview

Posted on 2009-05-04
12
319 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
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!

 

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 62 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 63 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 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