数据网格行列计算 [英] Data grid rows column calculation
本文介绍了数据网格行列计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要计算行的数据列
并将值显示在文本框中
如Amount = 10
数量= 10
数量= 10
数量= 10
我想在文本框中显示
我正在尝试此代码,但播种了rows的最后一个值.
double 最终= 0 ;
// 十进制Serial = Convert.ToInt32(dataGridView1.Rows [i] .Cells [0] .Value); 跨度>
十进制数量= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 2 ].Value);
十进制费率= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 3 ].Value);
十进制增值税= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 4 ].Value);
十进制 TotalPrice = Convert.ToInt32(Quantity * Rate);
十进制 TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 4 ].Value )/ 100 ;
TotalPrice = TempVatTax + TotalPrice;
dataGridView1.Rows [i] .Cells [ 5 ].Value = TotalPrice;
最终= Convert.ToDouble(TotalPrice);
// Final = Convert.ToDouble(txt_Total.Text + Final);
// 最终+ = CInt(row.Cells(0).Text);
txt_Total.Text = Convert.ToString(Final);
}
请告诉我解决方案
解决方案
我假设您正在循环使用Rows[i]
的东西?如果是这样,那么如果您希望Final成为累加总数,则将"="替换为"+ =":
最终= Convert.ToDouble(TotalPrice);成为
最终+ = Convert.ToDouble(TotalPrice);
其计算当前单元格并在文本框中显示双精度值
double LastTotal = 0 ; double 最终= 0 ; // 十进制Serial = Convert.ToInt32(dataGridView1.Rows [i] .Cells [0] .Value); 跨度> 十进制数量= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 0 ].Value); 十进制比率= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 1 ].Value); 十进制增值税= Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 2 ].Value); 十进制 TotalPrice = Convert.ToInt32(Quantity * Rate); 十进制 TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows [i] .Cells [ 3 ].Value )/ 100 ; TotalPrice = TempVatTax + TotalPrice; dataGridView1.Rows [i] .Cells [ 4 ].Value = TotalPrice; 最终= Convert.ToDouble(TotalPrice); // 将此代码添加到COde编辑器 如果(txt_Total.Text!= " ) { LastTotal = Convert.ToDouble(txt_Total.Text); } txt_Total.Text = Convert.ToString(Final + LastTotal);
I want to calculate the data columns of row
and show the value into text box
like Amount=10
Amount=10
Amount=10
Amount=10
and i want to show into text box
i m trying this code but is sowing the last value of rows.
double Final = 0; //decimal Serial = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); decimal Quantity = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value); decimal Rate = Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value); decimal vat = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value); decimal TotalPrice = Convert.ToInt32(Quantity * Rate); decimal TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value) / 100; TotalPrice = TempVatTax + TotalPrice; dataGridView1.Rows[i].Cells[5].Value = TotalPrice; Final = Convert.ToDouble(TotalPrice); //Final=Convert.ToDouble(txt_Total.Text+Final); //Final += CInt(row.Cells(0).Text); txt_Total.Text = Convert.ToString(Final); }
Please Tell me the solution解决方案I assume you are using this in a loop, from theRows[i]
stuff? If so, then if you want Final to be a cumulative total, then replace "=" with "+=":
Final = Convert.ToDouble(TotalPrice);Becomes
Final += Convert.ToDouble(TotalPrice);
its calculating the current cell and show double value in text box
double LastTotal=0; double Final = 0; //decimal Serial = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); decimal Quantity = Convert.ToDecimal(dataGridView1.Rows[i].Cells[0].Value); decimal Rate = Convert.ToDecimal(dataGridView1.Rows[i].Cells[1].Value); decimal vat = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value); decimal TotalPrice = Convert.ToInt32(Quantity * Rate); decimal TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value) / 100; TotalPrice = TempVatTax + TotalPrice; dataGridView1.Rows[i].Cells[4].Value = TotalPrice; Final = Convert.ToDouble(TotalPrice); //Add this Code to your COde Editor if (txt_Total.Text != "") { LastTotal = Convert.ToDouble(txt_Total.Text); } txt_Total.Text = Convert.ToString(Final+LastTotal);
这篇关于数据网格行列计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文