C#中DataGridView動態(tài)添加行及添加列的方法
更新時間:2015年09月15日 12:15:26 作者:我心依舊
這篇文章主要介紹了C#中DataGridView動態(tài)添加行及添加列的方法,涉及C#中DataGridView針對行與列動態(tài)操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#中DataGridView動態(tài)添加行及添加列的方法。分享給大家供大家參考。具體如下:
Datagridview添加列:
DataGridViewTextBoxColumn acCode = new DataGridViewTextBoxColumn(); acCode.Name = "acCode"; acCode.DataPropertyName = "acCode"; acCode.HeaderText = "A/C Code"; dgvVouchers.Columns.Add(acCode);
Datagridview創(chuàng)建行:
DataGridViewRow dr = new DataGridViewRow(); dr.CreateCells(dgvVouchers); //添加的行作為第一行 dgvVouchers.Rows.Insert(0, dr); //添加的行作為最后一行 dgvVouchers.Rows.Add(dr_new);
希望本文所述對大家的C#程序設計有所幫助。