如何在C#WPF中读取datagrid列值? [英] How to read datagrid column value in C# WPF?
本文介绍了如何在C#WPF中读取datagrid列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在wpf中有dataGrid,有一个名为'Sub Total'的列现在我想通过添加子总列的所有行来计算小计的总数。
喜欢
- 小计 -
10
20
30 br / >
点击Total按钮我想显示Total为60的消息。
如何在wpf DataGrid中执行此操作c#。
谢谢
Tink
我的尝试:
Hi,
I have dataGrid in wpf, there is a column named 'Sub Total' now I want to calculate the total from subtotal by adding the all rows of sub total column.
like
-- sub total --
10
20
30
on click of Total button I want to display the message that Total is 60.
How to do this in wpf DataGrid c#.
Thanks
Tink
What I have tried:
foreach (DataGridColumn column in grdBill.Columns)
{
???
}
我尝试了类似的但没有得到如何得到这个。
I tried something like but not getting how to get this.
推荐答案
试试这个>>
try this >>
private void calculate()
{
decimal sum1 = 0;
foreach (GridViewRow i in this.gv1.Rows)
{
decimal e = Convert.ToDecimal(i.Cells[5].Text.ToString());
sum1 = sum1 + e;
}
txtSubTotal.Text = sum1.ToString();
}
这篇关于如何在C#WPF中读取datagrid列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文