问题描述
嗨我有一个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
推荐答案
( ...)当我更改文本框中的数值时,除非它从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.
这篇关于如何在更改数量时计算文本框中产品的总价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!