Solved

Data Grid Formatting

Posted on 2006-07-21
1
239 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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