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

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

问题描述

什么是抢DataGridView的内容,并把这些值转换成一个列表在C#中的最佳方式是什么?


解决方案

 列表< MyItem>项目=新的List< MyItem>(); 
的foreach(在dataGridView1.Rows的DataGridViewRow DR)
{
MyItem项目=新MyItem();
的foreach(DataGridViewCell的DC IN dr.Cells)
{
...打造出MyItem ....基于DataGridViewCell.OwningColumn和DataGridViewCell.Value
}

items.Add(项目);
}


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);
        }

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

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