This is a migrated thread and some comments may be shown as answers.

FORMATCURRENCY COLUMNS

9 Answers 248 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Andrés David Santacoloma Isaza asked on 12 Nov 2010, 03:19 PM
Hi:

I have the following code for my gridview:

For i As Integer = 5 To 9
        DirectCast(GridViewGeneral.Columns(i), GridViewDataColumn).FormatString = "{0:C}"
Next

But the format of the columns doesn't change

Thanks.

9 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 03:40 PM
Hello,

What column type are you using? You should be adding a GridViewDecimalColumn and then setting the formatting in this way.

Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("Currency"))
Me.RadGridView1.Columns(0).FormatString = "{0:C}"

And this will format to currency as required.

hope that helps
Richard
0
Andrés David Santacoloma Isaza
Top achievements
Rank 1
answered on 12 Nov 2010, 04:12 PM
Hi:

my columns are create by a datasource. How modify their type?

Thanks.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 04:19 PM
Hello,

In your data, do you have a mix of types in the same column? I.e are they strings? If so, then you cannot format to currency and you would need to inspect each value in the CellFormatting event.

If your data source comes from a database or an object collection and the returned column is a decimal, then the radGridView will create a decimal column for you.

You can tell that it is a decimal column at runtime as the cell editor will be a SpinEditor (only allowing you to enter decimals).

If you can confirm, I will do my best to help
richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 12 Nov 2010, 11:06 PM
Hello Andres,

Where are you  calling that code?
Please add it to the DataBindingComplete event and it should work.

If it doesn't please specify the version of telerik controls are you using.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 12 Nov 2010, 11:59 PM
Hi,

It shouldn't matter where you are calling the Column.FormatString from Emanuel. It is fine for exmaple placing it before adding data as long as it is done after the column is created for the column index that you are specifiying.

Regards,
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 13 Nov 2010, 12:02 AM
Hello,

It matters, because you have to make sure that you have the columns created, and the first event that fires after data binding is of course the DataBindingComplete.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 12:13 AM
Hi Emanuel,

As I said. It doesn't matter as long as it is done after the column is created. Assuming that you are using a datasource to bind to the grid I agree, that DataBindingComplete is the correct place.
On an unbound grid, create your columns in form load, then add the Column format, then the data.

Regards,
Richard
0
Andrés David Santacoloma Isaza
Top achievements
Rank 1
answered on 13 Nov 2010, 02:27 PM
Hi Richard and Emanuel:

I solved the problem by changing the format of the fields in my database. Before, the columns were formatted text and I changed the format to number. So, the code I gave in my question is functioning properly.

I very much appreciate your answers because without them there would have solved my question.


David.
0
Richard Slade
Top achievements
Rank 2
answered on 13 Nov 2010, 02:31 PM
Glad that you have this sorted. Please could you mark any answers that you found helful as answer so others can quickly find the solution too.

All the best
richard
Tags
GridView
Asked by
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Andrés David Santacoloma Isaza
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or