i am unable to show currency format on DataGridView. Can you people look this code.
private void dataGridView1_DataBindingComplete(object sender,
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>
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";
Try adding this
objPreview.dataGridView1.Columns["Debit"].ValueType = Type.GetType("System.Decimal")
objPreview.dataGridView1.Columns["Credit"].ValueType = Type.GetType("System.Decimal")
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
Try adding the code @Pranay Rana suggested into the CellFormatting Event on the DataGridView:
private void NameOfYourGridGoesHere_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
this.NameOfYourGridGoesHere.Columns["UnitPrice"].DefaultCellStyle.Format = "c";
}
If you have already binded your DataSource to the DataGridView, you can set your cell style by setting each cell format like:
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells["Debit"].Style.Format = "c";
row.Cells["Credit"].Style.Format = "c";
}
Make sure your value is numerical.