Currency format in DataGridView in windows application
19,706
Solution 1
if it is windows form than write this code before you are binding data to the grid...something as below in the form consturctor...
public Form1()
{
this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "c";
}
if its ASP.Net
try something like DataFormatString="{0:c}"
<asp:BoundField HeaderText="Price/Unit"
DataField="UnitPrice" SortExpression="UnitPrice"
DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
Solution 2
Try adding this
objPreview.dataGridView1.Columns["Debit"].ValueType = Type.GetType("System.Decimal")
objPreview.dataGridView1.Columns["Credit"].ValueType = Type.GetType("System.Decimal")
Solution 3
Can you check ( breakpoint or something ) that DataBindingComplete event is fired . So at least we know its not that
( edited ) So if its fired check this maybe it will help
http://msdn.microsoft.com/en-us/library/k4sab6f9
Maybe by creating a new style it will help
Solution 4
Also you can use this for Windows Forms: (or its equivalent for WPF or ASP ,...)
yourColumn.DefaultCellStyle.Format = "#,#";
// And add below if you want
yourColumn.DefaultCellStyle.NullValue= "0";
Author by
Kiran Reddy
Updated on June 14, 2022Comments
-
Kiran Reddy about 2 years
i am unable to show currency format on DataGridView. Can you people look this code.
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { objPreview.dataGridView1.Columns["Debit"].DefaultCellStyle.Format = "c"; objPreview.dataGridView1.Columns["Credit"].DefaultCellStyle.Format = "c"; }