Solved

formatting a column in datagridview

Posted on 2009-05-04
12
314 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

16 Experts available now in Live!

Get 1:1 Help Now