我正在处理 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 回答
![?](http://img1.sycdn.imooc.com/545850ee0001798a02200220-100-100.jpg)
紫衣仙女
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;为似乎与您的问题相匹配……您希望将答案存储在单元格中。
![?](http://img1.sycdn.imooc.com/533e4c0500010c7602000200-100-100.jpg)
互换的青春
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);
- 2 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消