How to put € symbol in DataGridView

2

I have a DataGridView with numeric values and some of them represent monetary values, but the database comes just 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 you wanted and concatenate the value inside the Cell with the symbol.

In these two values I wanted to put the currency symbol, is it possible?

    
asked by anonymous 08.07.2017 / 13:02

1 answer

2

Use the DefaultCellStyle property to set the style to apply to the cells of a given column.

In this case, you must use the Format :

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

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

By default the provider 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"); 

On the string "C2" see:

08.07.2017 / 13:39