简体   繁体   中英

How to add a calculated custom column in datagridview?

I have a Win Form Application.

Where i use MySql Database. I have three column - Quyntity, sold, and returned.

I want to add a new custom column on datagrid view name - 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.

How can i do this ?

My Assumption is you are using DataTable to bind with you grid view. 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM