By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

formatting DataColumn.Expression

P: n/a
J
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how about
simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )"; //error
: Expression does not support String.Format
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

I think the burden of formatting should be put on a presentation tier code
(e.g. the DataGrid control) and not on a DataColumn - it's just not made to
be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how about simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )"; //error : Expression does not support String.Format


Nov 15 '05 #2

P: n/a
J
The example was formatting as currency, but the principal applies to
unlimited situations.
Don't think of it as formatting for the presentation layer, think of it as
building calculated datacolumns that require use of procedures, functions,
classes, whatever. To build any kind of calculated datacolumn, except for
the most simple, requires this functionality.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
Hi,

I think the burden of formatting should be put on a presentation tier code
(e.g. the DataGrid control) and not on a DataColumn - it's just not made to be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how

about
simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )";

//error
: Expression does not support String.Format

Nov 15 '05 #3

P: n/a
This seem to be limited by the allowed syntax in the Expression property
(please refer to the "DataColumn.Expression Property" topic in MSDN), which
resembles SQL and has no support for calling managed code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vo************@corp.supernews.com...
The example was formatting as currency, but the principal applies to
unlimited situations.
Don't think of it as formatting for the presentation layer, think of it as
building calculated datacolumns that require use of procedures, functions,
classes, whatever. To build any kind of calculated datacolumn, except for the most simple, requires this functionality.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
Hi,

I think the burden of formatting should be put on a presentation tier code (e.g. the DataGrid control) and not on a DataColumn - it's just not made

to
be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how

about
simply displaying the column formatted as a number with only 2 decimals (#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )";

//error
: Expression does not support String.Format



Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.