c# - 如何从datagridview的一列中读取数据

标签 c# winforms datagridview

我想从 datagridview 的一列中读取数据。我的 datagridview 包含许多列,但我想读取所有单元格,但只能从一列中读取。我使用此代码阅读了所有专栏:

foreach (DataGridViewColumn col in dataGridView1.Columns)
        col.Name.ToString();

但我想读取特定列中的所有单元格。

最佳答案

试试这个

string data = string.Empty;
int indexOfYourColumn = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
   data = row.Cells[indexOfYourColumn].Value;

关于c# - 如何从datagridview的一列中读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14977697/

相关文章:

c# - 在 linq to entities 查询中获取子项计数

c# - 强制创建惰性对象

C#标签从私有(private)方法接收信息(工具箱值)

c# - 解释 DrawArc 方法?

c# - 在 DataGridView 上托管自定义控件,这些控件从 DataTable 填充数据

c# 在运行时动态创建泛型列表

c# - LinQ with Count 和 Where 条件

c# - 恢复 C# Windows 窗体背景色

c# - BindingSource.Filter 最大长度

c# - DataSource 改变前的 DataGridView 事件