加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#DataGridView.Rows.ToString()

发布时间:2020-12-16 09:38:01 所属栏目:百科 来源:网络整理
导读:我试图将每个行的值存储在一个字符串中. 如果我尝试做DataGridView.Rows.ToString()我得到 System.Windows.Forms.DataGridViewRowCollection 甚至不接近我的需要. 有任何想法吗? 解决方法 我认为你正在寻找每行的东西.如果是这样,我建议如下. private stati
我试图将每个行的值存储在一个字符串中.

如果我尝试做DataGridView.Rows.ToString()我得到

System.Windows.Forms.DataGridViewRowCollection

甚至不接近我的需要.

有任何想法吗?

解决方法

我认为你正在寻找每行的东西.如果是这样,我建议如下.

private static IEnumerable<string> GetRowValues(this DataGridView dgv)
  {
     var list = new List<string>(dgv.Rows.Count);
     foreach (DataGridViewRow row in dgv.Rows)
     {
        var sb = new StringBuilder();
        foreach (DataGridViewCell cell in row.Cells)
        {
           sb.Append(cell.ToString());
        }
        list.Add(sb.ToString());
     }
     return list.AsReadOnly();
  }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读