C#-DataGridView设置列不显示, 发现有小BUG,
Form1.Designer.cs文件中会把dataGridVIew1.Columns.AddRange() 部分的代码消失 .
例如: 设置UserID列不显示, 建议,直接在代码文件中在USERID属性代码段后面输入"this.UserID.Visible = false;" 代码,完整的 如代码段2所示 .
代码段1:
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.UserID,
this.UserName,
this.Password,
this.DeptID,
this.DeptCode,
this.DeptName});
this.dataGridView1.Location = new System.Drawing.Point(16, 30);
this.dataGridView1.Name = "dataGridView1";
代码段2:
//
// UserID
//
this.UserID.DataPropertyName = "UserID";
this.UserID.HeaderText = "UserID";
this.UserID.Name = "UserID";
this.UserID.Visible = false;