如何在更改数量时计算文本框中产品的总价值 [英] How to calculate total value of products in a text box when qty is changed

查看:92
本文介绍了如何在更改数量时计算文本框中产品的总价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一个wpf数据网格视图,其中有列数量的价格和总数,当我添加一个产品总数将按qty *价格计算我有一个文本框,它将存储总和的总和但当我更改数值时文本框不会更改,除非它从数量上失去焦点帮助



我尝试过:



十进制总数= 0;



for(int i = 0; i< dgvProducts.Items.Count; i ++)

{

BLProducts blpro = dgvProducts.Items [i] as BLProducts;

total + = blpro.qty * blpro.price;

}





txtproductTotal.Text = Parsing.ParsetoRound(total,CommonVariables.DecimalPlaces);



我在celleditending中使用过这种方法

hi I had a wpf datagrid view for products which have columns qty price and total when I add one product total will be calculated by qty * price I had a text box which will store sum of total but when I change qty value in textbox is not changed until and unless it loses its focus from qty kindly help

What I have tried:

decimal total= 0;

for (int i = 0; i < dgvProducts.Items.Count; i++)
{
BLProducts blpro = dgvProducts.Items[i] as BLProducts;
total+= blpro.qty * blpro.price;
}


txtproductTotal.Text = Parsing.ParsetoRound(total, CommonVariables.DecimalPlaces);

I had used this method in celleditending

推荐答案

如果我理解你的话,尤其是这句话:

If i understand you well, especially this statement:
girishmdr [ ^ ]写道:

( ...)当我更改文本框中的数值时,除非它从qty失去焦点,否则不会更改

(...) when I change qty value in textbox is not changed until and unless it loses its focus from qty





这是WPF控件的正常行为。请阅读:路由事件概述 [ ^ ] - WPF输入事件部分以找出原因。



This is normal behviour of WPF controls. Please read this: Routed Events Overview[^] - WPF Input Events part to find out why.


这篇关于如何在更改数量时计算文本框中产品的总价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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