c# - 在C#中将DataGridView的内容转换为List

标签 c# .net list datagridview

获取 DataGridView 的内容并将这些值放入 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# - 在C#中将DataGridView的内容转换为List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4281101/

相关文章:

c# - 从另一个对象中获取 SignalR Core 中的 Hub 上下文

javascript - 如何从后台代码访问这些动态创建的控件?

c# - 调试期间鼠标悬停 (DataTip) 后自动实例化的属性

c# - 如何避免加载不必要的程序集

c# - C# 中包含 1000 条记录的二进制文件格式

list - 长度有序子集?

android - 为什么列表中的值被新值覆盖?

c# - 将部分填充的 DTO 映射到域对象

.net - 将 WPF(需要 STAThread)与无法与 STAThread 配合使用的 API 结合使用

c# - 用于比较的订单日期列表