Question Format Unbound DataGridView

dkap

New member
Joined
Dec 3, 2014
Messages
2
Programming Experience
Beginner
Hi All,
Does anyone know how to format cells to currency in an unbound datagridview.
I have tried the following:
dgv1.Columns[1].DefaultCellStyle.Format="c" but no go.

I thought I read somewhere that you cannot format an unbound grid to currency, only bound grids ?

Any help would be appreciated..

Thanks:ambivalence:
 
You can format unbound columns, but you can't format string values. Convert the values to numbers and they will be formatted.
If the values are entered by user you can set the columns ValueType property to have them converted to a numeric type.
 
Thanks for the quick reply JohnH,
The values I have in my grid are numbers.. they are decimals.
I have just tried the opposite and it worked. I converted the decimal to string using the .ToString() function and was able to format.

The variables below Twelve & TwentyFour are both decimals.
string[] row = new string[] { "12 Months", Twelve.ToString("$ ##,##0.00")};
dgvResults.Rows.Add(row);
row = new string[] { "24 Months", TwentyFour.ToString("$ ##,##0.00")};
dgvResults.Rows.Add(row);
 
The values I have in my grid are numbers.. they are decimals.
If they won't format it means they are already strings. Formatting is the process of converting a number to a formatted string.
 
Back
Top Bottom