简体   繁体   English

如何从C#中的数据网格视图获取值?

[英]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.

相关问题 如何使用C#从neo4j数据库获取数据并将其绑定到网格视图中? - How to get data from neo4j database and bind it into a grid view using C#? CodeGo.net&gt;如何将数据从网格视图传递到报表查看器? - c# - How to pass the data from grid view to report Viewer? 如何从combox向C#中的数据网格视图添加值 - How to Add a value from combox to data grid view in C# 如何从网格获取值到c#控制器 - How to get values from grid to c# controller 如何在数据网格视图列中查看多个数据C# - How to view multiple data in data grid view column c# 在数据网格视图中将值从long转换为TimeSpan(带有SQL Server的C#) - Converting values from long to TimeSpan in data grid view (C# with SQL Server) 如何通过asp.net C#中的查询字符串在网格视图中将数据从一个类获取到另一类 - How to get data from one class to another class in grid view through query string in asp.net C# C#数据网格视图 - C# Data Grid View 从数据网格视图中选择一部分数据C# - Selecting a portion of data from a Data grid view c# 以另一种形式将数据从一个数据网格视图发送到另一个数据网格视图 - sending data from 1 data grid view to another data grid view in another form c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM