zoukankan      html  css  js  c++  java
  • #将datagridview转datatable

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Windows.Forms;
    using System.Linq;
    using System.Text;

    namespace Test

    {
        public class DataTransition
        {
            /// <summary>
            /// datagridview转datatable
            /// </summary>
            /// <param name="dv"></param>
            /// <returns></returns>
            public static DataTable dvtodt(DataGridView dv)
            {
                DataTable dt = new DataTable();
                DataColumn dc;
                for (int i = 0; i < dv.Columns.Count; i++)
                {
                    dc = new DataColumn();
                    dc.ColumnName = dv.Columns[i].HeaderText.ToString();
                    dt.Columns.Add(dc);
                }
                for (int j = 0; j < dv.Rows.Count; j++)
                {
                    DataRow dr = dt.NewRow();
                    for (int x = 0; x < dv.Columns.Count; x++)
                    {
                        dr[x] = dv.Rows[j].Cells[x].Value;
                    }
                    dt.Rows.Add(dr);
                }
                return dt;
            }
        }
    }

  • 相关阅读:
    设计原则
    git 教程
    git新建分支及提交代码到分支
    DataTemplateSelector介绍
    Semaphore 类 的使用理解C#
    C#中Finalize方法的问题
    WPF原理剖析——路由事件
    WPF自学入门(四)WPF路由事件之自定义路由事件
    路由事件
    commandBinding 的命令
  • 原文地址:https://www.cnblogs.com/moss_tan_jun/p/2014139.html
Copyright © 2011-2022 走看看