从DataGridView在C#中读取数据 [英] Reading data from DataGridView in C#

查看:218
本文介绍了从DataGridView在C#中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能读取C#从 DataGridView的数据?我想读的数据列于表。我如何通过线定位?

How can I read data from DataGridView in C#? I want to read the data appear in Table. How do I navigate through lines?

推荐答案

for (int rows = 0; rows < dataGrid.Rows.Count; rows++)
{
     for (int col= 0; col < dataGrid.Rows[rows].Cells.Count; col++)
    {
        string value = dataGrid.Rows[rows].Cells[col].Value.ToString();

    }
} 

例如不使用索引

foreach (DataGridViewRow row in dataGrid.Rows)
{ 
    foreach (DataGridViewCell cell in row.Cells)
    {
        string value = cell.Value.ToString();

    }
}

这篇关于从DataGridView在C#中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆