【问题标题】:How to multiply value in datagridview column by a textbox in a button click and get output same column c#如何将datagridview列中的值乘以按钮单击中的文本框并获得输出相同的列c#
【发布时间】:2019-05-28 06:59:21
【问题描述】:

我需要将 Datagrid 视图中的值乘以单击按钮中的文本框。 例子 Datagrid 视图列中的值(单元格 [10])列索引 [“存款”] 值 1000、2000、300.75 我需要在文本框中输入月数并单击按钮并希望得到结果:示例:按钮单击后文本框值为 2 / 存款值应为 2000、4000、601.50 注意:我需要将这些值更改为同一列 ["Deposit"] 单元格 [10],而不是另一列

请参阅下面的代码,我试图获得输出,但它不起作用,谁能帮我解决这个问题?

var xs = listA.Exists(listB);
for (int i = 0; i < DataGridView1.Rows.Count; i++)
     {
       double val1, val2, tot;
       double.TryParse(Txtmonth.Text, out val1);
       val2 = Convert.ToDouble(DataGridView1.Rows[i].Cells[10].Value);
       tot = (val1 * val2);

     }

【问题讨论】:

  • 在计算出tot 之后,您不会将值附加回cell 添加DataGridView1.Rows[i].Cells[10].Value = tot;

标签: c# datagridview


【解决方案1】:

试试这个

for (int i = 0; i < DataGridView1.Rows.Count; i++)
     {
       double val1, val2;
       double.TryParse(Txtmonth.Text, out val1);
       DataGridView1.Rows[i].Cells[10].Value = Convert.ToDouble(DataGridView1.Rows[i].Cells[10].Value) * val1;
     }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多