Solved

formatting a column in datagridview

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now