程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> csharp: DataTable Rename ColumnName,csharpcolumnname

csharp: DataTable Rename ColumnName,csharpcolumnname

編輯:C#入門知識

csharp: DataTable Rename ColumnName,csharpcolumnname


  enum ChangeNume
        {
            /// <summary>
            /// 簡體
            /// </summary>
            gbk=1,
            /// <summary>
            /// 英文
            /// </summary>
            en=2,
            /// <summary>
            /// 繁體
            /// </summary>
            big=3,
            ko=4,
            jp=5,
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        DataTable setData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("patner", typeof(int));
            dt.Columns.Add("time", typeof(DateTime));
            dt.Rows.Add(1, "dgeo", 0, "2015-01-02");
            dt.Rows.Add(2, "geovindu", 1, "2015-03-03");
            dt.Rows.Add(3, "gess", 1, "2015-03-23");
            dt.Rows.Add(4, "dfadfd", 2, "2015-04-03");
            return dt;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dv"></param>
        /// <param name="lname"></param>
        private DataTable setGridViewName(DataTable dv, ChangeNume lname)
        {
            DataTable dt = dv;
            switch (lname)
            {
                case ChangeNume.gbk:
                    dt.Columns[0].ColumnName = "序號";
                    dt.Columns[1].ColumnName = "名稱";
                    dt.Columns[2].ColumnName = "父節點";
                    dt.Columns[3].ColumnName = "日期";
                    break;
                case ChangeNume.big:
                    dt.Columns[0].ColumnName = "序號";
                    dt.Columns[1].ColumnName = "名稱";
                    dt.Columns[2].ColumnName = "父節點";
                    dt.Columns[3].ColumnName = "日期";
                    break;
                case ChangeNume.en:
                    dt.Columns[0].ColumnName = "id";
                    dt.Columns[1].ColumnName = "name";
                    dt.Columns[2].ColumnName = "patner";
                    dt.Columns[3].ColumnName = "time";
                    break;
                default:
                    dt.Columns[0].ColumnName = "序號";
                    dt.Columns[1].ColumnName = "名稱";
                    dt.Columns[2].ColumnName = "父節點";
                    dt.Columns[3].ColumnName = "日期";
                    break;
            }
            return dt;
        }

        /// <summary>
        /// 
        /// </summary>
        public Form2()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form2_Load(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = setGridViewName(setData(), ChangeNume.en);

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            this.dataGridView2.DataSource = setGridViewName(setData(), ChangeNume.big);
        }

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved