从 datagridview 列表达式调用自定义方法
使用 c#、vs2008 winforms
我有一个 datagridview,我以编程方式绑定到绑定源,该绑定源绑定到带有 1 个表的数据集。
使用 sqlAdaptor 填充数据集后,我想向数据集添加一个新列,并在新列中使用从调用表单中的自定义方法派生的结果填充它。
代码例如如下,但我得到一个“表达式包含未定义的函数调用 this.Test()
是否允许在列的表达式中调用方法,
提前感谢任何帮助 欢呼
this.dsProdOrdLst1.ProdOrder.Columns.Add("sOrderType", typeof(string),
"this.Test(order_type)"); // order_type is another column in the dataset
形式类中其他地方的方法
public int Test(int orderType)
{
return 10; //return a test value
}
using c#, vs2008 winforms
I have a datagridview that i am programtically binding to a binding source, that is bound to a dataset with 1 table.
After filling the dataset using the sqlAdaptor, i want to add a new column to the dataset, and in the new column populate it with a result derived from a call to a custom method in the form.
Code Eg is bellow but i get a "Expression contains undefined function call this.Test()
Is it allowed to call methods as such in the expression of the column
thanks in advance for any help
cheers
this.dsProdOrdLst1.ProdOrder.Columns.Add("sOrderType", typeof(string),
"this.Test(order_type)"); // order_type is another column in the dataset
elsewhere in the form class is the method
public int Test(int orderType)
{
return 10; //return a test value
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,这些表达式(称为 ADO.NET 表达式)没有调用任何类型的用户定义函数的方式。然而,手动填充新列应该是微不足道的:
或者,您可能能够在 ADO.NET 表达式中实现整个函数,但您实际上只想对非常简单的函数执行此操作,否则将会一团糟:
< 的文档code>DataColumn.Expression 有一个受支持函数的列表(向下滚动很远才能找到它)。
AFAIK, these expressions (known as ADO.NET expressions) have no way of calling any kind of user defined functions. It should however by trivial to manually populate the new column:
Alternatively, you might be able to implement your entire function in an ADO.NET expression, but you really only want to do this for very simple functions, as otherwise it will be a mess:
The documentation of
DataColumn.Expression
has a list of supported functions (scroll pretty far down to find it).