Solved

formatting a column in datagridview

Posted on 2009-05-04
12
316 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports vb.net 2 39
VB.Net - TypeInitializer Error 25 25
Sql server insert 13 27
vb.net winforms sizing/resolution? 4 29
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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