formatting DataColumn.Expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J

    #1

    formatting DataColumn.Expression

    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.Get Type("System.St ring");
    colTax.ColumnNa me = "tax";
    myTable.Columns .Add(colTax);
    colTax.Expressi on = "String.Format( \"{0:C}\",\"amo unt*taxrate\" )"; //error
    : Expression does not support String.Format


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: formatting DataColumn.Expr ession

    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

    Bring the power of unit testing to VS .NET IDE

    "J" <j> wrote in message news:vntvobj31h p35d@corp.super news.com...[color=blue]
    > Is there anyway to format a calculated datacolumn? I would like the
    > following column to display as money (formatted as $#,##0.00). Or how[/color]
    about[color=blue]
    > 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.Get Type("System.St ring");
    > colTax.ColumnNa me = "tax";
    > myTable.Columns .Add(colTax);
    > colTax.Expressi on = "String.Format( \"{0:C}\",\"amo unt*taxrate\" )";[/color]
    //error[color=blue]
    > : Expression does not support String.Format
    >
    >[/color]

    Comment

    • J

      #3
      Re: formatting DataColumn.Expr ession

      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-code@no-spam-please.hotpop.c om> wrote
      in message news:Otm1z6BjDH A.2636@TK2MSFTN GP11.phx.gbl...[color=blue]
      > 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[/color]
      to[color=blue]
      > 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:vntvobj31h p35d@corp.super news.com...[color=green]
      > > Is there anyway to format a calculated datacolumn? I would like the
      > > following column to display as money (formatted as $#,##0.00). Or how[/color]
      > about[color=green]
      > > 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.Get Type("System.St ring");
      > > colTax.ColumnNa me = "tax";
      > > myTable.Columns .Add(colTax);
      > > colTax.Expressi on = "String.Format( \"{0:C}\",\"amo unt*taxrate\" )";[/color]
      > //error[color=green]
      > > : Expression does not support String.Format
      > >
      > >[/color]
      >[/color]


      Comment

      • Dmitriy Lapshin [C# / .NET MVP]

        #4
        Re: formatting DataColumn.Expr ession

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

        --
        Dmitriy Lapshin [C# / .NET MVP]
        X-Unity Test Studio

        Bring the power of unit testing to VS .NET IDE

        "J" <j> wrote in message news:vo3c5ofde2 a28d@corp.super news.com...[color=blue]
        > 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[/color]
        for[color=blue]
        > the most simple, requires this functionality.
        >
        > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
        > in message news:Otm1z6BjDH A.2636@TK2MSFTN GP11.phx.gbl...[color=green]
        > > Hi,
        > >
        > > I think the burden of formatting should be put on a presentation tier[/color][/color]
        code[color=blue][color=green]
        > > (e.g. the DataGrid control) and not on a DataColumn - it's just not made[/color]
        > to[color=green]
        > > 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:vntvobj31h p35d@corp.super news.com...[color=darkred]
        > > > Is there anyway to format a calculated datacolumn? I would like the
        > > > following column to display as money (formatted as $#,##0.00). Or how[/color]
        > > about[color=darkred]
        > > > simply displaying the column formatted as a number with only 2[/color][/color][/color]
        decimals[color=blue][color=green][color=darkred]
        > > > (#,##0.00)?
        > > > In the sample below, amount and taxrate are existing DataColumn's.
        > > >
        > > > DataColumn colTax = new DataColumn();
        > > > colTax.DataType = System.Type.Get Type("System.St ring");
        > > > colTax.ColumnNa me = "tax";
        > > > myTable.Columns .Add(colTax);
        > > > colTax.Expressi on = "String.Format( \"{0:C}\",\"amo unt*taxrate\" )";[/color]
        > > //error[color=darkred]
        > > > : Expression does not support String.Format
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]

        Comment

        Working...