关于Windows应用程序的问题 [英] Question Regarding windows Application
问题描述
如何将datagridview的2行的值相加,结果将显示在文本框中...?
假设有一个名为"Productname"和"Price"的2列的datagridview.我有两个product(pen,paper)n两个price(25.75,68).我需要在文本框中将(25.75 + 68)的结果四舍五入如94.00.
How to add the value of 2 rows of a datagridview and the result will shown in a textbox...?
suppose have a datagridview of 2 column named "Productname" and "Price".i have two product(pen,paper) n two price(25.75,68).I need the result of (25.75+68) in a textbox with rounded value as 94.00.
推荐答案
尝试这样做:
try to do this way :
double[] price = new[] { 25.75, 68 };
double sum = 0;
for (int i = 0; i < 2; i++)
{
sum +=Math.Round(price[i]);
}
Console.WriteLine(sum);
Console.ReadLine();
u可以使用下面的数据表计算方法
u can use datatable compute method like below
totalprice= dtproduct.Compute("SUM(Price)", String.Empty).ToString
然后将totalprise的值分配给您想要的文本框,但是您只能这样做,如果您在数据表中只有2行,如果您想对特定的列求和,那么还有另一种方法
谢谢
then assign the value of totalprise to your desiered textbox , but u can only do it , if u have only 2 rows in datatable , if u want to sum on specific columns then there is another way
Thanks
这篇关于关于Windows应用程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!