Click here to Skip to main content
15,944,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a datagridview which displays my records in currency format BUT I have a particular column which I wanna display it values as an Integer.

The column i wanna change and what it displays
[AreaCode]
 15,00 €
 25,00 €
 60,00 €


My expectation:
[AreaCode]
  15
  25
  60

And here is my code which isn't working:

C#
private void dgv1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
var columnname = "AreaCode";
if (e.ColumnIndex == dgv1.Columns[columnname].Index)
            {
                //Get the datagridview cell
       DataGridViewCell cell = dgv1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                if (cell != null)
                {
      this.dgv1.Columns["AreaCode"].DefaultCellStyle.Format = "D4";

                }


            }

}
Posted
Comments
Sergey Alexandrovich Kryukov 1-Apr-15 10:42am    
"Isn't working" is not informative. Why handling cell formatting? Why not just setting DefaultCellStyle permanently?
—SA
mikybrain1 2-Apr-15 6:51am    
Ja i did that already but it autmactically changed the column AreaCode too which i don' wanna have the figures to be currency.

That's why I'm asking for help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900