[英]How to add a calculated custom column in datagridview?
I have a Win Form Application. 我有一个Win Form申请表。
Where i use MySql Database. 我在哪里使用MySql数据库。 I have three column - Quyntity, sold, and returned.
我有三列-Quyntity,已售出并退回。
I want to add a new custom column on datagrid view name - available_quyntity. 我想在datagrid视图名称-available_quyntity上添加一个新的自定义列。 And it will show the result of (Quyntity - sold) + returned.
它将显示(质量-已售出)+返回的结果。
Eg - a column have Qyn - 10, Sold - 6, Returned - 2. So, the result of the available_quyntity will be 6. 例如-一列有Qyn-10,Sold-6,Returned-2。因此,available_quyntity的结果将为6。
How can i do this ? 我怎样才能做到这一点 ?
My Assumption is you are using DataTable to bind with you grid view. 我的假设是您正在使用DataTable与您的网格视图绑定。 here is a sample code that can do this task.
这是可以完成此任务的示例代码。
DataTable dt = your datasource;
DataColumn dc = new DataColumn();
dc.ColumnName = "NameForNewColumn";
dc.DataType = typeof(WhatEverDataTypeYouWant);
dc.Expression = "(Quyntity - sold) + returned";
dt.Columns.Add(dc);
DataGridView.DataSource = dt;
DataGridView.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.