擴展的財產上述
private List<string> _list = new List<string>();
private List<string> ColList
{
get { return _list; }
set { _list = value; }
}
private DataGridViewTextBoxColumn AddColumns(string Name)
{
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn()
col.Name = Name;
col.HeaderText = Name;
col.HeaderCell.Style.WrapMode = DataGridViewTriState.NotSet;
col.ToolTipText = Name;
col.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
col.MinimumWidth = 80;
col.DataPropertyName =Name;
return col;
}
然後,您可以遍歷ColumnList和添加,也可以設置基本屬性列
foreach(string s in ColList)
{ datagridview1.Columns.Add(AddColumns(s)); }
@belinq你覺得這有用嗎? – V4Vendetta 2011-04-28 11:37:04
謝謝,它的工作原理。我已經替換了'public列表 _list = new List ();'用數組'public string [] Columns;',然後我更容易添加'baseGridView.Columns = new string [2] {「Name 「,」密碼「}; '你在想什麼? –
VeecoTech
2011-04-28 13:37:23