日期:2014-05-17 浏览次数:20923 次
this.GV_ColumnInfo.AutoGenerateColumns = false; this.GV_ColumnInfo.DataSource =你要绑定的dt; DataGridViewColumn fieldNameColumn = new DataGridViewTextBoxColumn(); fieldNameColumn.HeaderText = "field_name"; fieldNameColumn.DataPropertyName = "field-name"; this.GV_ColumnInfo.Columns.Add(fieldNameColumn); DataGridViewColumn idColumn = new DataGridViewTextBoxColumn(); idColumn.HeaderText = "id"; idColumn.DataPropertyName = "id"; this.GV_ColumnInfo.Columns.Add(idColumn); DataGridViewColumn identifierColumn = new DataGridViewTextBoxColumn(); identifierColumn.HeaderText = "identifier"; identifierColumn.DataPropertyName = "identifier"; this.GV_ColumnInfo.Columns.Add(identifierColumn); //下拉列表绑定时候,DataPropertyName和ValueMember做对比, DataGridViewComboBoxColumn typeColumn = new DataGridViewComboBoxColumn(); typeColumn.DataSource = GetComBoxDataSource(); typeColumn.Width = 200; typeColumn.DataPropertyName = "type"; typeColumn.DisplayMember = "Text"; typeColumn.ValueMember = "Values"; typeColumn.HeaderText = "type"; //typeColumn = ComboBoxStyle.DropDownList; this.GV_ColumnInfo.Columns.Add(typeColumn); DataGridViewColumn lengthColumn = new DataGridViewTextBoxColumn(); lengthColumn.HeaderText = "length"; lengthColumn.DataPropertyName = "length"; this.GV_ColumnInfo.Columns.Add(lengthColumn);