如何乘法数据网格查看单元格值 [英] How to multiplication data grid view cell values

查看:53
本文介绍了如何乘法数据网格查看单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 am creating windows application using c# 2010, here i am using data grid view for billing purpose, here i want, i am enter first cell values in below method and how to show multiplication result on second column

Ex :

first cell       second cell
10x10             100

how to create above method give me any one idea





我尝试过:





What I have tried:

How to multiplication data grid view cell values

推荐答案

请参阅此处: DataColumn.Expression属性 [ ^ ] - 它包含一个示例。
See here: DataColumn.Expression Property[^] - it includes an example.


我建​​议您使用两个不同的列而不是单列,这将使数据输入,甚至更简单的实现。



然后处理gridview的CellEndEdit事件。并且在那个事件中计算并将值分配给第三列



类似于

private void dataGridView1_CellEndEdit(object sender,DataGridViewCellEventArgs e)

{

int数量,费率;

if(int.TryParse(dataGridView1.Rows [e.RowIndex] .Cells [quantity] .Value.ToString(),out quantity)&& int.TryParse(dataGridView1.Rows [e.RowIndex] .Cells [rate]。Value.ToString(),out rate))

{

int price = quantity * rate;

dataGridView1.Rows [e.RowIndex] .Cells [price]。Value = price.ToString();

}

}
I would suggest you to use two different columns instead of single column, this will make data entry and even less complicated for implementation.

And then handle the CellEndEdit event of your gridview. And in that event calculate and assign the value to the third column

something like
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int quantity,rate;
if (int.TryParse(dataGridView1.Rows[e.RowIndex].Cells["quantity"].Value.ToString(), out quantity) && int.TryParse(dataGridView1.Rows[e.RowIndex].Cells["rate"].Value.ToString(), out rate))
{
int price = quantity * rate;
dataGridView1.Rows[e.RowIndex].Cells["price"].Value = price.ToString();
}
}


这篇关于如何乘法数据网格查看单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆