[英]How to get values from data grid view in c#?
I tried with this code.. 我尝试使用此代码。
for (int i = 0; i < datagridItemEntry.RowCount; i++)
{
int a = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[4].Value);
int b = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[5].Value);
int c = a * b;
datagridItemEntry.SelectedRows[i].Cells[6].Value = c.ToString();
}
I want value of cell 4 & 5 to be get multiplied and the result should be reflect in cell 6.. Nothing is happening with the above code.. Help me with the proper code.. 我希望将单元格4和5的值相乘,结果应反映在单元格6中。以上代码没有任何反应..帮助我提供正确的代码..
Your problem may be here 您的问题可能在这里
datagridItemEntry.SelectedRows[i].Cells[6].Value = c.ToString();
Replace .SelectedRows
to .Rows
将
.SelectedRows
替换为.Rows
for (int i = 0; i < datagridItemEntry.RowCount; i++)
{
int a = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[4].Value);
int b = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[5].Value);
int c = a * b;
datagridItemEntry.Rows[i].Cells[6].Value = c.ToString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.