melegant
asked on
How to format with $ in Datagrid and Decimal Type Column?
Hi,
I have a datatable that I am filling with a SQL Adapter. The sql query looks something like
SELECT price1,price2 from prices
Now, I do some calculations and want to display the values in the datatable with a $.
such as:
(See code snipped)
Here is the error:
Input string was not in a correct format.Couldn't store <$1,125.00> in sell Column. Â Expected type is Decimal.
grr, how can I show the values with a $?
I have a datatable that I am filling with a SQL Adapter. The sql query looks something like
SELECT price1,price2 from prices
Now, I do some calculations and want to display the values in the datatable with a $.
such as:
(See code snipped)
Here is the error:
Input string was not in a correct format.Couldn't store <$1,125.00> in sell Column. Â Expected type is Decimal.
grr, how can I show the values with a $?
num3 = ((Convert.ToDecimal(mSubTable.Rows[i][5]) * (Convert.ToDecimal(mSubTable.Rows[i][6]) * .01M) + Convert.ToDecimal(mSubTable.Rows[i][5])));
mSubTable.Rows[i][7] = num3.ToString("$#,#,##.#0");
you cant put a string in a decimal column, you have 2 options"
add another column with datatype string and put the values with $ symbols in that column, or if your datagrid has predefined columns then you can enter a format of "C" for that column and it will format it as a $ string for display.
if your datagrid needs in-place editing which needs to update the datasource then you will need to use the second method.
add another column with datatype string and put the values with $ symbols in that column, or if your datagrid has predefined columns then you can enter a format of "C" for that column and it will format it as a $ string for display.
if your datagrid needs in-place editing which needs to update the datasource then you will need to use the second method.
ASKER
Solar,
My grid is being populated with a sqladapter and I am mapping the schema from the source. How can I format the column after the fact with the C as you mentioned?
My grid is being populated with a sqladapter and I am mapping the schema from the source. How can I format the column after the fact with the C as you mentioned?
Cast the columns to strings in the SQL as I already mentioned, What DB are you using?
ASKER
Hi Red,
I can do that yes, however I would have to go and alter a bunch of SP's which I am not crazy about doing.
The issue here is that I have an Infragistics Ultragrid where I am displaying the values..and I want to display the values as currency. I am using SQL and my datatype for these particular fields is Decimal (18,0).
I know how to parse it once it is a currency (Numberstyles.Any with a Decimal.Parse).
There must be a way for the column to take a deicmal as currency..it would be crazy not to!
I can do that yes, however I would have to go and alter a bunch of SP's which I am not crazy about doing.
The issue here is that I have an Infragistics Ultragrid where I am displaying the values..and I want to display the values as currency. I am using SQL and my datatype for these particular fields is Decimal (18,0).
I know how to parse it once it is a currency (Numberstyles.Any with a Decimal.Parse).
There must be a way for the column to take a deicmal as currency..it would be crazy not to!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ha..that is it..and it was simple. Thanks! Have to do it during the grid init event...
e.Layout.Bands[0].Columns[ 6].Format = "$##,##.00";
e.Layout.Bands[0].Columns[
you will need to cast your column to string, this can be done in your SQL for example this is how you would achieve this in Oracle
SELECT to_char(price1), to_char(price2) from prices
then when the columns are bound to your grid they are considered to be strings instead of decimal columns, and you can add the $.
RedK