为了账号安全,请及时绑定邮箱和手机立即绑定

C# 乘以 2 数据网格从输入中查看列并将结果放在第三列中

C# 乘以 2 数据网格从输入中查看列并将结果放在第三列中

C#
茅侃侃 2021-06-11 15:20:54
我正在处理 POS winforms 应用程序,但遇到了麻烦,datagridview 是由用户输入填充的,通过条码扫描仪,然后用户调整数据网格视图内的数量,我想做的是什么时候用户更改 Quantity 的值(默认设置为 1)它会乘以第二列价格并在第三列中显示结果A 列(输入的值)x B 列 = 结果到 C 列我试过使用这个代码,但没有运气            private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)            {                for (int i = 0; i < dataGridView1.Rows.Count; i++)                {            int a =dataGridView1.Rows[i][0].value;            int b =dataGridView1.Rows[i][1].value;            int c = a*b;            c=dataGridView1.Rows[i][2].value;      }它给了我错误 14 无法将 [] 索引应用于“System.Windows.Forms.DataGridViewRow”类型的表达式
查看完整描述

2 回答

?
紫衣仙女

TA贡献1839条经验 获得超15个赞

您需要使用类的Cells属性DataGridViewRow


用:


int a = dataGridView1.Rows[i].Cells[0].Value;

int b = dataGridView1.Rows[i].Cells[1].Value;


int c = a * b;


dataGridView1.Rows[i].Cells[2].Value = c;

请注意,我将最后一行更改dataGridView1.Rows[i].Cells[2].Value = c;为似乎与您的问题相匹配……您希望将答案存储在单元格中。


查看完整回答
反对 回复 2021-06-20
?
互换的青春

TA贡献1797条经验 获得超6个赞

decimal s = Convert.ToDecimal(dataGridView_DaginaAdd_SellInovice.CurrentRow.Cells[10].Value);

            decimal s1 = Convert.ToDecimal(dataGridView_DaginaAdd_SellInovice.CurrentRow.Cells[11].Value);

            decimal s13 = s + s1; Convert.ToDecimal(dataGridView_DaginaAdd_SellInovice.CurrentRow.Cells[12].Value = s13);



查看完整回答
反对 回复 2021-06-20
  • 2 回答
  • 0 关注
  • 136 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信