1. 程式人生 > >datagridview 代碼添加列

datagridview 代碼添加列

方式 int key urn sha 流水號 str sts per

       int column_key = 0;
        private DataGridViewTextBoxColumn column_add(string name)
        {
            DataGridViewTextBoxColumn txtClum = new DataGridViewTextBoxColumn();
            txtClum.DataPropertyName = "txt" + column_key++.ToString();
            txtClum.Name = "txt" + column_key++.ToString() ;
            txtClum.HeaderText = name;
            return txtClum;
        }    

  //調用column_add添加列

        dgvCostSum.Columns.Add(column_add("日期"));
            dgvCostSum.Columns.Add(column_add("姓名/單位"));
            dgvCostSum.Columns.Add(column_add("流水號"));
            dgvCostSum.Columns.Add(column_add("體檢金額"));
            dgvCostSum.Columns.Add(column_add("收費員"));
            dgvCostSum.Columns.Add(column_add("支付方式"));

  

datagridview 代碼添加列