Solved

Data Grid Formatting

Posted on 2006-07-21
1
236 Views
Last Modified: 2012-06-27
I am binding a data grid to an sql table and one of my columns is a currency. Is there anyway that I can format that one column when it is being loaded?
0
Comment
Question by:mwhodges
1 Comment
 
LVL 4

Accepted Solution

by:
jtaylor8181 earned 250 total points
ID: 17157138
How are you trying to format it, alignment, font, etc.  If that is the case you can do it programmatically.

With datagrid

.Columns("currency").HeaderText = "Price"

.Columns("currency").DefaultCellStyle.Font = New Font FontFamily.GenericSansSerif, 10.0F, FontStyle.Bold)

.Columns("currency").DefaultCellStyle.Alignment = Forms.DataGridViewContentAlignment.MiddleRight

End With

Then I believe for sql, if you store a value in a database table as currency it will return with extra decimal places, example 10.99 - 10.9900, so what will have to do is format those prices as well.  What you could to is use a dataview and then use a for loop to go through each of the rows and reformat it.

me.m_dv as dataview

For i As Integer = 0 To Me.m_dv.Count - 1

Me.m_dv(i).Item("currency") = Format(Me.m_dv(i).Item("currency"), "0.00")

Next

I hope this is what you were looking for.

jtaylor


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

18 Experts available now in Live!

Get 1:1 Help Now