ListView設定列,并給列的Name屬性賦值,
但是是要用ListView1.Colomns[0].Name時,卻發現這個值為空
到 .Designer.cs文件里去看卻發現 只給Text屬性賦值Name屬性沒有賦值,設計時填寫的a只作為一個變量,並不是Name的值
this.a.Text = "列1";
//
// b
//
this.b.Text = "列2";
//
// c
//
this.c.Text = "列3";
//
// d
//
this.d.Text = "列4";
發現這個問題就好辦了,已是手動給Name賦值,這樣ListView1.Colomns[0].Name就能取到值了
this.a.Name = "a";
this.a.Text = "列1";
//
// b
//
this.b.Name = "b";
this.b.Text = "列2";
//
// c
//
this.c.Name = "c";
this.c.Text = "列3";
//
// d
//
this.d.Name = "d";
this.d.Text = "列4";