在C#中将DataGridView的内容转换为List [英] Convert contents of DataGridView to List in C#

查看:102
本文介绍了在C#中将DataGridView的内容转换为List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中获取 DataGridView 的内容并将这些值放入列表的最佳方法是什么?

What is the best way to grab the contents of a DataGridView and place those values into a list in C#?

推荐答案

        List<MyItem> items = new List<MyItem>();
        foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
            MyItem item = new MyItem();
            foreach (DataGridViewCell dc in dr.Cells)
            { 
                ...build out MyItem....based on DataGridViewCell.OwningColumn and DataGridViewCell.Value  
            }

            items.Add(item);
        }

这篇关于在C#中将DataGridView的内容转换为List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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