如何将Windows C#代码更改为WPF C#代码 [英] How to change windows C# code to WPF C# code

查看:148
本文介绍了如何将Windows C#代码更改为WPF C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有问题,如何将此代码转换为wpf c#code.please帮我me.thanks提前





hello everyone i have problem in that how to convert this code to wpf c# code.please help me.thanks in advance


foreach (DataGridViewRow row in dgvQuotionitem.Rows)
               {
                   row.Cells[3].Value = Convert.ToDecimal(row.Cells[1].Value) * Convert.ToDecimal(row.Cells[2].Value);
                   decimal discper = (Convert.ToDecimal(row.Cells[3].Value) / 100) * Convert.ToDecimal(row.Cells[4].Value);
                   row.Cells[5].Value = Convert.ToDecimal(row.Cells[3].Value) - discper;
                   txtTotalcost.Text = Convert.ToString(Convert.ToDecimal(txtTotalcost.Text) + Convert.ToDecimal(row.Cells[5].Value));
               }





我的尝试:



i发现foreach(dgvQuotation.Columns中的DataGridColumn列)

其他代码我不知道该怎么做



What I have tried:

i found that foreach (DataGridColumn column in dgvQuotation.Columns)
other code i dont know how to do

推荐答案

如果我正确理解你的问题,你现在通过在DataGridView中循环行计算总数。



虽然基本上可以用例如WPF中的DataGrid来完成不推荐它。而是尝试根据数据到达网格的数据源进行计算。例如,如果数据来自DataTable对象,则根据数据表的行进行计算。或者甚至更好地考虑将两个单元格作为计算字段添加到数据表中,然后对数据表中的所有行求和。



有关DataTable中这些功能的更多信息,请参阅 DataColumn.Expression属性(System.Data) [ ^ ]和 DataTable.Compute方法(字符串,字符串)(System.Data) [ ^ ]
If I understand your question correctly, you currently calculate the total by looping rows in a DataGridView.

While the same could basically be done for example with DataGrid in WPF I wouldn't recommend it. Instead try to do the calculations based on the data source where the data comes to the grid. For example if the data comes from a DataTable objects, do the calculations based on the rows of the data table. Or even better consider adding the two cells as calculated fields in the data table and then sum all the rows in the data table.

For more information about these features in DataTable, see DataColumn.Expression Property (System.Data)[^] and DataTable.Compute Method (String, String) (System.Data)[^]


这篇关于如何将Windows C#代码更改为WPF C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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