zoukankan      html  css  js  c++  java
  • C#如何从DataGridView控件数据,转成获取DataTable

     public DataTable GetDgvToTable(DataGridView dgv)
            {
                DataTable dt
    = new DataTable();
               
    for (int count = 0; count < dgv.Columns.Count; count++)
                {
                    DataColumn dc
    = new DataColumn(dgv.Columns[count].Name.ToString());
                    dt.Columns.Add(dc);
                }
               
    for (int count = 0; count < dgv.Rows.Count; count++)
                {
                    DataRow dr
    = dt.NewRow();
                   
    for (int countsub = 0; countsub < dgv.Columns.Count; countsub++)
                    {
                        dr[countsub]
    = Convert.ToString(dgv.Rows[count].Cells[countsub].Value);
                    }
                    dt.Rows.Add(dr);
                }
               
    return dt;
            }

  • 相关阅读:
    汉诺塔问题
    Java中的int类型取值范围
    unsigned 类型
    CharBuffer
    铺地砖问题(递归)
    汉诺塔简略
    Long类型的构造方法被遗弃,代替的是valueOf
    坏掉的项链
    挤牛奶
    修理牛棚
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/2008782.html
Copyright © 2011-2022 走看看