How to put € symbol on Datagridview

Asked

Viewed 118 times

2

I have a Datagridview with numerical values and some of them represent monetary values, but from the database comes only the number and wanted to put the currency symbol in front of the value.

This is the code I use to load my Datagridview;

public void carregarDataGridView3()
    {
        Abastecimento_Negocio abastecimento_Negocio = new Abastecimento_Negocio();
        dataGridView3.DataSource = null;
        dataGridView3.DataSource = abastecimento_Negocio.conusltarMedias(mesPassado);
        dataGridView3.Update();
        dataGridView3.Refresh();
        dataGridView3.ClearSelection();
        FontDataGrid3();
    }

My idea was to select the column I wanted and concatenate the value inside Cell with the symbol.

inserir a descrição da imagem aqui

In these two values wanted to put the symbol of the coin, it is possible?

1 answer

2


Use the property Defaultcellstyle to define the style to be applied to cells in a given column.

In this case you must use the property Format:

dataGridView3.Columns[1].DefaultCellStyle.Format = "C2";

Replace the index according to the column you want to format.

By default the preview used for formatting is Currentuiculture

If you want to use a specific use the Formatprovider property:

dataGridView3.Columns[1].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("pt-PT"); 

About the string "C2" see:

  • Thanks for the help. Thanks also for sharing about C2.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.