问题
I would like to change behavior of DataColumn.Expression
so that when I write:
DataColumn.Expression = "MyMethod(Price)"
It will call MyMethod, pass value from Price column into it and display evaluated value.
How can I acomplish this?
回答1:
Not possible. The expression parser behind the Expression property is simple and not extensible. Making arbitrary function calls is not one of its capabilities. There are several ways to work around this, especially ones that don't require an expensive reflection lookup. Consider the DataTable.RowChanged event for example.
回答2:
A way around this is to make your function a calculated field like in databases and spredsheets. It is possible to make advanced calculated fields. You need to rewrite your function to an expression and then use [Price] to refer to the source column. As I understand your question it makes it possible to do what you intend. The syntax for expression can be found here.
I know this is a late answer to the question but it might help others looking into how to do this.
来源:https://stackoverflow.com/questions/1707897/customize-datacolumn-expression-handling-in-c-sharp